cesanta / mjs

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

Invalid memory read in mjs_execute() at mjs.c:9320 #243

Open fengzhengzhan opened 1 year ago

fengzhengzhan commented 1 year ago

Invalid memory read in mjs at function mjs_execute in mjs.c:9320.

Environment

Ubuntu 18.04, 64 bit

Steps to reproduce

  1. download file
    git clone https://github.com/cesanta/mjs.git mjs
    cd mjs
    git checkout d6c06a6
  2. compile libming with ASAN
    clang -fsanitize=address mjs.c -o mjs_asan
  3. command for reproducing the error
    ./mjs_asan -f poc

    Download poc: mjs_invalid-memory-read_mjs9320.zip

ASAN report

> ./mjs_asan -f mjs_invalid-memory-read_mjs9320
AddressSanitizer:DEADLYSIGNAL
=================================================================
==23749==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x00000050e0d0 bp 0x7ffdec19de70 sp 0x7ffdec19dcb0 T0)
==23749==The signal is caused by a WRITE memory access.
==23749==Hint: address points to the zero page.
    #0 0x50e0d0 in mjs_execute /root/compiler1804/aflgo_dataset/mjs-issues-57/mjs.c:9320:46
    #1 0x50c2ce in mjs_exec_internal /root/compiler1804/aflgo_dataset/mjs-issues-57/mjs.c:9503:5
    #2 0x50c410 in mjs_exec_file /root/compiler1804/aflgo_dataset/mjs-issues-57/mjs.c:9526:11
    #3 0x50f8df in main /root/compiler1804/aflgo_dataset/mjs-issues-57/mjs.c:11783:13
    #4 0x7fe50601e082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
    #5 0x41c3cd in _start (/home/fzz/Desktop/STFGFuzz/Programs/mjs-issues-57/seeds_crash/mjs_asan+0x41c3cd)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/compiler1804/aflgo_dataset/mjs-issues-57/mjs.c:9320:46 in mjs_execute
==23749==ABORTING
marvi3 commented 1 year ago

Hello, I tried to reproduce the problem but when following you instructions on the build step with clang and the adress-sanitizer I ran into the following problem:

usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
clang: error: linker command failed with exit code 1