public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/107908] New: A null pointer dereference bug was missed by UBsan at -O0
@ 2022-11-29 8:50 shaohua.li at inf dot ethz.ch
2022-11-29 9:06 ` [Bug sanitizer/107908] " pinskia at gcc dot gnu.org
2022-11-29 9:10 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2022-11-29 8:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107908
Bug ID: 107908
Summary: A null pointer dereference bug was missed by UBsan at
-O0
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: sanitizer
Assignee: unassigned at gcc dot gnu.org
Reporter: shaohua.li at inf dot ethz.ch
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org
Target Milestone: ---
`gcc-trunk -O0 -fsanitize=undefined -fno-sanitize-recover=all` misses the
NULL-pointer-dereference, while `gcc-trunk -Ox -fsanitize=address
-fno-sanitize-recover=all` (x=1, 2, 3, or s) can detect it.
Compiler explorer: https://godbolt.org/z/x7jo7eYYh
% cat a.c
int a;
int main() {
int *c;
for (int d = 0; d < 1; d++)
*c == (a = 0);
__builtin_printf("%d\n", *c);
}
%
% gcc-tk -O0 -fsanitize=undefined -fno-sanitize-recover=all a.c &&./a.out
1
% gcc-tk -O1 -fsanitize=undefined -fno-sanitize-recover=all -w a.c &&./a.out
a.c:5:5: runtime error: load of null pointer of type 'int'
% gcc-tk -O3 -fsanitize=undefined -fno-sanitize-recover=all -w a.c &&./a.out
a.c:5:5: runtime error: load of null pointer of type 'int'
%
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug sanitizer/107908] A null pointer dereference bug was missed by UBsan at -O0
2022-11-29 8:50 [Bug sanitizer/107908] New: A null pointer dereference bug was missed by UBsan at -O0 shaohua.li at inf dot ethz.ch
@ 2022-11-29 9:06 ` pinskia at gcc dot gnu.org
2022-11-29 9:10 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-29 9:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107908
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
c is uninitialized so it could hold any value including but not limited to a
null pointer.
In -O0 case, it just happens to have a non null value.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug sanitizer/107908] A null pointer dereference bug was missed by UBsan at -O0
2022-11-29 8:50 [Bug sanitizer/107908] New: A null pointer dereference bug was missed by UBsan at -O0 shaohua.li at inf dot ethz.ch
2022-11-29 9:06 ` [Bug sanitizer/107908] " pinskia at gcc dot gnu.org
@ 2022-11-29 9:10 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-29 9:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107908
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
If you used -ftrivial-auto-var-init=zero you would get the runtime error:
/app/example.cpp:6:5: runtime error: load of null pointer of type 'int'
With -ftrivial-auto-var-init=pattern you get:
/app/example.cpp:6:5: runtime error: load of misaligned address
0xfefefefefefefefe for type 'int', which requires 4 byte alignment
0xfefefefefefefefe: note: pointer points here
<memory cannot be printed>
Which is also expected.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-29 9:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-29 8:50 [Bug sanitizer/107908] New: A null pointer dereference bug was missed by UBsan at -O0 shaohua.li at inf dot ethz.ch
2022-11-29 9:06 ` [Bug sanitizer/107908] " pinskia at gcc dot gnu.org
2022-11-29 9:10 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).