Menu

#11 Heap-based Buffer Overflow in the get_line() function

v1.0 (example)
open
nobody
None
5
2024-03-26
2019-06-19
No

Hi,

While fuzzing mcpp with American Fuzzy Lop, I found a Heap-based
Buffer Overflow in the get_line() function, in support.c L1957.

Attaching a reproducer, issue can be reproduced by running:

mcpp test-get_line

Regards,
Frederic Cambus.

=================================================================
==13894==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6310000007ff at pc 0x00000055e553 bp 0x7ffd9dfabbd0 sp 0x7ffd9dfabbc8
READ of size 1 at 0x6310000007ff thread T0
#0 0x55e552 in get_line /home/fcambus/mcpp-2.7.2/src/support.c:1957:13
#1 0x558ba2 in parse_line /home/fcambus/mcpp-2.7.2/src/support.c:1657:15
#2 0x550214 in get_ch /home/fcambus/mcpp-2.7.2/src/support.c:1580:13
#3 0x513c1b in mcpp_main /home/fcambus/mcpp-2.7.2/src/main.c:626:17
#4 0x513396 in main /home/fcambus/mcpp-2.7.2/src/main.c:421:5
#5 0x7fee45cfdb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
#6 0x41a149 in _start (/home/fcambus/tmp-mcpp/mcpp+0x41a149)

0x6310000007ff is located 1 bytes to the left of 65536-byte region [0x631000000800,0x631000010800)
allocated by thread T0 here:
#0 0x4da000 in malloc (/home/fcambus/tmp-mcpp/mcpp+0x4da000)
#1 0x556ae4 in xmalloc /home/fcambus/mcpp-2.7.2/src/support.c:2336:28
#2 0x55b52b in get_file /home/fcambus/mcpp-2.7.2/src/support.c:2281:20
#3 0x56bb31 in add_file /home/fcambus/mcpp-2.7.2/src/system.c:3540:12
#4 0x51318a in main /home/fcambus/mcpp-2.7.2/src/main.c:412:5
#5 0x7fee45cfdb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/fcambus/mcpp-2.7.2/src/support.c:1957:13 in get_line
Shadow bytes around the buggy address:
0x0c627fff80a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fff80b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fff80c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fff80d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fff80e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c627fff80f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa[fa]
0x0c627fff8100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c627fff8110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c627fff8120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c627fff8130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c627fff8140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 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
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
==13894==ABORTING

1 Attachments

Discussion

  • Frederic Cambus

    Frederic Cambus - 2019-06-19

    Attached the wrong file, here is the reproducer.

     
  • John Brandwood

    John Brandwood - 2024-03-26

    For anyone looking at this thread currently ... this was fixed back in 2019 by the Debian maintainers with 04-gniibe-fix-12.patch

    I have applied a slightly modified version of that patch here ...
    https://github.com/jbrandwood/mcpp/commit/1d56f3287b20bb3876be1a0cc132e06dada5256b

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.