https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105217
Bug ID: 105217
Summary: Likely wrong code with -D_FORTIFY_SOURCE=3
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: marxin at gcc dot gnu.org
CC: siddhesh at gcc dot gnu.org
Target Milestone: ---
Created attachment 52781
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52781&action=edit
test-case
Isolated from autogen, where we originally created the following issue:
https://sourceforge.net/p/autogen/bugs/212/
I isolated that to the attached test-case:
$ head -c 20k </dev/urandom > /tmp/1
$ gcc snippet.c -O2 -D_FORTIFY_SOURCE=3 -g && ./a.out /tmp/1
fread: data=0x2052c0, rem_sz=16340
.. read rdct=16340
realloc to=0x20a490-0x20f489 (newsize=20473)
.. diferent buffer!
fread: data=0x20e484, rem_sz=4096
.. read rdct=4096
realloc to=0x20a490-0x210489 (newsize=24569)
fread: data=0x20f484, rem_sz=4096
*** buffer overflow detected ***: terminated
Aborted (core dumped)
$ clang snippet.c -O2 -D_FORTIFY_SOURCE=3 -g && ./a.out /tmp/1
fread: data=0x4052c0, rem_sz=16340
.. read rdct=16340
realloc to=0x40a490-0x40f489 (newsize=20473)
.. diferent buffer!
fread: data=0x40e484, rem_sz=4096
.. read rdct=4096
realloc to=0x40a490-0x410489 (newsize=24569)
fread: data=0x40f484, rem_sz=4096
.. read rdct=44
fread: data=0x40f4b0, rem_sz=4052
.. read rdct=0