Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

heap-buffer-overflow at Jsi_DSAppendLen src/jsiDString.c:109 #24

Closed
kvenux opened this issue Oct 22, 2020 · 1 comment
Closed

heap-buffer-overflow at Jsi_DSAppendLen src/jsiDString.c:109 #24

kvenux opened this issue Oct 22, 2020 · 1 comment

Comments

@kvenux
Copy link

kvenux commented Oct 22, 2020

Build environment:

Ubuntu 16.04
gcc 5.4.0
version: 17c32ef
build command:
export JSI__SANITIZE=1
make
test command: ./jsish poc

POC

jsish-1021-000022.txt

Description

Below is the ASAN outputs.

=================================================================
==139092==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000a694 at pc 0x7f881c593935 bp 0x7ffeee682e00 sp 0x7ffeee6825a8
READ of size 5 at 0x60200000a694 thread T0
#0 0x7f881c593934 in __asan_memcpy (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x8c934)
#1 0x5c18de in memcpy /usr/include/x86_64-linux-gnu/bits/string3.h:53
#2 0x5c18de in Jsi_DSAppendLen src/jsiDString.c:109
#3 0x5ecbb3 in Jsi_UtfSubstr src/jsiUtf8.c:130
#4 0x4e2180 in StringSubstrCmd src/jsiString.c:145
#5 0x4c4f20 in jsi_FuncCallSub src/jsiProto.c:244
#6 0x73e470 in jsiFunctionSubCall src/jsiEval.c:793
#7 0x73e470 in jsiEvalFunction src/jsiEval.c:828
#8 0x73e470 in jsiEvalCodeSub src/jsiEval.c:1253
#9 0x7509a7 in jsi_evalcode src/jsiEval.c:2188
#10 0x4c5eed in jsi_FuncCallSub src/jsiProto.c:220
#11 0x73e07c in jsiFunctionSubCall src/jsiEval.c:793
#12 0x73e07c in jsiEvalFunction src/jsiEval.c:828
#13 0x73e07c in jsiEvalCodeSub src/jsiEval.c:1253
#14 0x7509a7 in jsi_evalcode src/jsiEval.c:2188
#15 0x7534fb in jsi_evalStrFile src/jsiEval.c:2494
#16 0x49ae7e in Jsi_Main src/jsiInterp.c:917
#17 0xc07b32 in jsi_main src/main.c:44
#18 0x7f881ba3383f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2083f)
#19 0x434fc8 in _start (/home/keven/Fuzzing/jsish-1021/jsish+0x434fc8)

0x60200000a694 is located 0 bytes to the right of 4-byte region [0x60200000a690,0x60200000a694)
allocated by thread T0 here:
#0 0x7f881c59f602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
#1 0x49f4b2 in Jsi_Malloc src/jsiUtils.c:52

SUMMARY: AddressSanitizer: heap-buffer-overflow ??:0 __asan_memcpy
Shadow bytes around the buggy address:
0x0c047fff9480: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9490: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff94a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff94b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff94c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c047fff94d0: fa fa[04]fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
0x0c047fff94e0: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
0x0c047fff94f0: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 00 fa
0x0c047fff9500: fa fa 00 fa fa fa 00 00 fa fa 00 00 fa fa 00 fa
0x0c047fff9510: fa fa 00 00 fa fa 00 00 fa fa 00 fa fa fa 00 00
0x0c047fff9520: fa fa 00 00 fa fa 00 fa fa fa 00 00 fa fa 00 00
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
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
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
==139092==ABORTING

pcmacdon pushed a commit that referenced this issue Oct 22, 2020
FossilOrigin-Name: e80b49a9efc27115df10a40211059af608d7ed7d53f4de3712140e1baf1cca7c
@pcmacdon
Copy link
Owner

Yech, UTF. I've fixed the crash, but can't guarantee it's correct. I need to review UTF support sometime in the future.

FYI, I made the following test script change to let it complete:

--- /tmp/t22.jsi 2020-10-22 12:07:02.974697870 -0700
+++ /tmp/t22_new.txt 2020-10-22 11:52:10.222922772 -0700
@@ -44,7 +44,7 @@
return ''' + escape(String.fromCharCode(charCode)) + ''';
return ''' + expected + ''';
}
-function testIDNCharacter(charCode, expected, expectedNotFirstCharacter) {
+function testIDNCharacter(charCode, expected, expectedNotFirstCharacter='') {
if (expectedNotFirstCharacter == null)
expectedNotFirstCharacter = expected;
}
@@ -202,4 +202,5 @@
testIDNCharacter(65377, 'does not encode', '.');
testIDNCharacter(65279, 'does not encode', '');
}
-successfullyParsed = true;
+var successfullyParsed = true;
+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants