pcmacdon / jsish

Jsi is a small, C-embeddable javascript interpreter with tightly woven Web and DB support.
https://jsish.org/
MIT License
42 stars 9 forks source link

MEMLEAK NOW: Heap-use-after-free src/jsiObj.c:339 in Jsi_ObjFree #83

Closed hope-fly closed 2 years ago

hope-fly commented 2 years ago
Jsish revision

Commit: 9fa798e

Version: v3.5.0

Build platform

Ubuntu 18.04.5 LTS (Linux 5.4.0-44-generic x86_64)

Build steps
export CFLAGS='-fsanitize=address'
make
Test case
var __instance = Object;
__instance.exec = RegExp;

try {
        $ERROR('Error' + (__instance.exec("1")));
} catch (e) {
}

Execution steps & Output
$ ./jsish/jsish poc.js
==22083==ERROR: AddressSanitizer: heap-use-after-free on address 0x6080000127e8 at pc 0x5569eb9fb061 bp 0x7ffdf3af1950 sp 0x7ffdf3af1940
READ of size 4 at 0x6080000127e8 thread T0
    #0 0x5569eb9fb060 in Jsi_ObjFree src/jsiObj.c:339
    #1 0x5569eb8e3aa0 in jsiInterpDelete src/jsiInterp.c:1943
    #2 0x5569ec0fa047 in jsi_main src/main.c:49
    #3 0x7f90875e2bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
    #4 0x5569eb889969 in _start (/usr/local/bin/jsish+0xe8969)

0x6080000127e8 is located 72 bytes inside of 96-byte region [0x6080000127a0,0x608000012800)
freed by thread T0 here:
    #0 0x7f90882517a8 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xde7a8)
    #1 0x5569eb8cf073 in regExpFree src/jsiInterp.c:588

previously allocated by thread T0 here:
    #0 0x7f9088251d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x5569eb8faaa4 in Jsi_Calloc src/jsiUtils.c:57
    #2 0x5569ec1a6faf  (/usr/local/bin/jsish+0xa05faf)

SUMMARY: AddressSanitizer: heap-use-after-free src/jsiObj.c:339 in Jsi_ObjFree
Shadow bytes around the buggy address:
  0x0c107fffa4a0: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c107fffa4b0: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c107fffa4c0: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd

  0x0c107fffa4d0: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c107fffa4e0: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fa
=>0x0c107fffa4f0: fa fa fa fa fd fd fd fd fd fd fd fd fd[fd]fd fd
  0x0c107fffa500: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c107fffa510: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c107fffa520: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c107fffa530: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c107fffa540: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==22083==ABORTING
pcmacdon commented 2 years ago

This is no longer a crash, but rather a memory leak. I'm unsure as to which fix changed this.

pcmacdon commented 2 years ago

I'm combining this with issue #17, and closing this one.