Hello.
I found a global-buffer-overflow bug in gnuplot.
Please confirm.
Thanks.
OS: CentOS 7
version: gnuplot 5.3 patchlevel 0
=================================================================
==1239==ERROR: AddressSanitizer: global-buffer-overflow on address 0x08b6ebe1 at pc 0x0847225b bp 0xbfca8898 sp 0xbfca888c
WRITE of size 1 at 0x08b6ebe1 thread T0
#0 0x847225a in do_enh_writec /home/karas/gnuplot-gnuplot-main/src/term.c:2202:26
#1 0x8473014 in enhanced_recursion /home/karas/gnuplot-gnuplot-main/src/term.c:2275:3
#2 0x8524d6f in ENHCANVAS_put_text /home/karas/gnuplot-gnuplot-main/src/../term/canvas.trm:1536:20
#3 0x84656e3 in write_multiline /home/karas/gnuplot-gnuplot-main/src/term.c:792:3
#4 0x8170a34 in do_key_sample /home/karas/gnuplot-gnuplot-main/src/boundary.c:1170:3
#5 0x8262c95 in do_plot /home/karas/gnuplot-gnuplot-main/src/graphics.c:704:7
#6 0x8344322 in eval_plots /home/karas/gnuplot-gnuplot-main/src/plot2d.c:3401:2
#7 0x818ae75 in plot_command /home/karas/gnuplot-gnuplot-main/src/command.c:1821:5
#8 0x8180f3a in command /home/karas/gnuplot-gnuplot-main/src/command.c:630:2
#9 0x8180f3a in do_line /home/karas/gnuplot-gnuplot-main/src/command.c:420
#10 0x82f5364 in load_file /home/karas/gnuplot-gnuplot-main/src/misc.c:405:10
#11 0x831bcb2 in main /home/karas/gnuplot-gnuplot-main/src/plot.c:650:3
#12 0xb7394636 in __libc_start_main /build/glibc-KM3i_a/glibc-2.23/csu/../csu/libc-start.c:291
#13 0x806a347 in _start (/home/karas/gnuplot-gnuplot-main/src/gnuplot+0x806a347)
0x08b6ebe1 is located 0 bytes to the right of global variable 'enhanced_text' defined in 'term.c:188:7' (0x8b6e7e0) of size 1025
SUMMARY: AddressSanitizer: global-buffer-overflow /home/karas/gnuplot-gnuplot-main/src/term.c:2202:26 in do_enh_writec
Shadow bytes around the buggy address:
0x2116dd20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x2116dd30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x2116dd40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x2116dd50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x2116dd60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x2116dd70: 00 00 00 00 00 00 00 00 00 00 00 00[01]f9 f9 f9
0x2116dd80: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
0x2116dd90: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
0x2116dda0: 04 f9 f9 f9 f9 f9 f9 f9 00 00 f9 f9 f9 f9 f9 f9
0x2116ddb0: 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
0x2116ddc0: 01 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
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
Left alloca redzone: ca
Right alloca redzone: cb
==1239==ABORTING
Nope.
I can't reproduce that one, either in gdb or in valgrind.
I'm sorry I took your time.
No error occurs in a clean environment.
Thanks.
Hello,
I will reproduce this problem.
Can you check again?
I uploaded the docker file.
Thanks.
The script file "do_enh_writec" tries to feed a 36 kbyte quoted string of binary garbage via the command line. In other words, this is not a failure mode that you could reasonably trigger interactively or from a script that was working half-way reasonably. Notice that the failure showing in the dump you provide is inside a system-specific library support routine that implements the C language library call strlen()
__strlen_ia32 () at ../sysdeps/i386/i686/multiarch/../../i586/strlen.S:51
I think gnuplot is an innocent victim here.
If you are generating these failure cases using a fuzzer, I suggest that you only allow it to generate valid ascii (or utf8) input, not random binary junk. That's where the interesting failure modes lie.
Thank you for your reply.
fuzzing is difficult to create valid inputs by entering random data.
Happy New Year. :)