Skip to content

Commit 5ca302a

Browse files
lzaoralkdudka
andcommitted
parser-gcc: implement parsing of UBSAN reports
Co-authored-by: Lukáš Zaoral <[email protected]> Co-authored-by: Kamil Dudka <[email protected]> Resolves: #108
1 parent 08968d4 commit 5ca302a

9 files changed

+102
-1
lines changed

Diff for: src/lib/parser-common.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#define RE_PATH_URL "http(?:s)?://[^:]+(?::[0-9]+)?[^:]+"
3434
#define RE_PATH RE_PATH_LOCAL "|" RE_PATH_URL
3535

36-
#define RE_EVENT_GCC "(?:(?:(?:fatal|internal) )?[A-Za-z][A-Za-z0-9_-]+)(?:\\[[^ \\]]+\\])?"
36+
#define RE_EVENT_GCC "(?:(?:(?:fatal|internal|runtime) )?[A-Za-z][A-Za-z0-9_-]+)(?:\\[[^ \\]]+\\])?"
3737
#define RE_EVENT_PROSPECTOR "(?:[A-Z]+[0-9]+\\[[a-z0-9-]+\\])"
3838
#define RE_EVENT RE_EVENT_GCC "|" RE_EVENT_PROSPECTOR
3939

Diff for: src/lib/parser-gcc.cc

+25
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ class Tokenizer: public ITokenizer {
103103
RE("^(?<file>[^:]+):(?<line>[0-9]+)() " /* file:line */
104104
RE_FNC_SMATCH /* fnc */
105105
" ([a-z]+): (.*)$") /* evt: msg */;
106+
107+
const RE reUbsanScope_ =
108+
RE("^\\s*#\\d+ (0x[[:xdigit:]]+) in ([^ ]+) " /* address, fnc */
109+
/* file:line OR executable+address */
110+
"(?:(?<file>[^:]+):(?<line>[0-9]+)|\\((?<file>[^+]+)\\+(?<line>0x[[:xdigit:]]+)\\))"
111+
/* BuildId */
112+
"(?: \\(BuildId: [[:xdigit:]]+\\))?$");
106113
};
107114

108115
EToken Tokenizer::readNext(DefEvent *pEvt)
@@ -158,6 +165,11 @@ EToken Tokenizer::readNext(DefEvent *pEvt)
158165
pEvt->msg = sm[/* fnc */ 4] + "(): ";
159166
pEvt->msg += sm[/* msg */ 6];
160167
}
168+
else if (boost::regex_match(line, sm, reUbsanScope_)) {
169+
tok = T_MSG;
170+
pEvt->event = "note";
171+
pEvt->msg = sm[/* fnc */ 2] + "() at " + sm[/* address */ 1];
172+
}
161173
else
162174
return T_UNKNOWN;
163175

@@ -570,6 +582,7 @@ struct GccPostProcessor::Private {
570582
const ImpliedAttrDigger digger;
571583

572584
void transGccAnal(Defect *pDef) const;
585+
void transUbsan(Defect *pDef) const;
573586
void polishGccAnal(Defect *pDef) const;
574587
void polishClangAnal(Defect *pDef) const;
575588
void transSuffixGeneric(Defect *pDef, const std::string, const RE &) const;
@@ -619,6 +632,17 @@ void GccPostProcessor::Private::transGccAnal(Defect *pDef) const
619632
keyEvt.msg = sm[/* msg */ 1];
620633
}
621634

635+
void GccPostProcessor::Private::transUbsan(Defect *pDef) const
636+
{
637+
if ("COMPILER_WARNING" != pDef->checker)
638+
return;
639+
640+
// UBSAN always uses 'runtime error' for its key event
641+
DefEvent &keyEvt = pDef->events[pDef->keyEventIdx];
642+
if (keyEvt.event == "runtime error")
643+
pDef->checker = "UBSAN_WARNING";
644+
}
645+
622646
void GccPostProcessor::Private::polishGccAnal(Defect *pDef) const
623647
{
624648
if ("GCC_ANALYZER_WARNING" != pDef->checker)
@@ -677,6 +701,7 @@ void GccPostProcessor::Private::transSuffixGeneric(
677701
void GccPostProcessor::apply(Defect *pDef) const
678702
{
679703
d->transGccAnal(pDef);
704+
d->transUbsan(pDef);
680705
d->transSuffixGeneric(pDef, "CLANG_WARNING", d->reClangWarningEvt);
681706
d->transSuffixGeneric(pDef, "COMPILER_WARNING", d->reGccWarningEvt);
682707
d->transSuffixGeneric(pDef, "SHELLCHECK_WARNING", d->reShellCheckId);

Diff for: tests/csgrep/0111-gcc-parser-ubsan-simple-args.txt

Whitespace-only changes.

Diff for: tests/csgrep/0111-gcc-parser-ubsan-simple-stdin.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
byteorder.h:83:9: runtime error: load of misaligned address 0x556e3e877805 for type 'const uint32_t', which requires 4 byte alignment
2+
0x556e3e877805: note: pointer points here
3+
b5 21 00 00 6c 00 00 07 ff 65 a0 b8 03 05 2f 74 65 78 74 0e 70 d6 f0 d2 4d 97 21 a4 81 00 00 a0
4+
^
5+
test.c:2:23: runtime error: load of null pointer of type 'char'

Diff for: tests/csgrep/0111-gcc-parser-ubsan-simple-stdout.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Error: UBSAN_WARNING:
2+
byteorder.h:83:9: runtime error: load of misaligned address 0x556e3e877805 for type 'const uint32_t', which requires 4 byte alignment
3+
0x556e3e877805: note: pointer points here
4+
# b5 21 00 00 6c 00 00 07 ff 65 a0 b8 03 05 2f 74 65 78 74 0e 70 d6 f0 d2 4d 97 21 a4 81 00 00 a0
5+
# ^
6+
7+
Error: UBSAN_WARNING:
8+
test.c:2:23: runtime error: load of null pointer of type 'char'

Diff for: tests/csgrep/0112-gcc-parser-ubsan-bt-args.txt

Whitespace-only changes.

Diff for: tests/csgrep/0112-gcc-parser-ubsan-bt-stdin.txt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
byteorder.h:83:9: runtime error: load of misaligned address 0x556e3e877805 for type 'const uint32_t', which requires 4 byte alignment
2+
0x556e3e877805: note: pointer points here
3+
b5 21 00 00 6c 00 00 07 ff 65 a0 b8 03 05 2f 74 65 78 74 0e 70 d6 f0 d2 4d 97 21 a4 81 00 00 a0
4+
^
5+
#0 0x556e3dc9349f in IVALu /builddir/build/BUILD/rsync-3.2.3/byteorder.h:83
6+
#1 0x556e3dc9349f in IVAL /builddir/build/BUILD/rsync-3.2.3/byteorder.h:124
7+
#2 0x556e3dc9349f in raw_read_int /builddir/build/BUILD/rsync-3.2.3/io.c:921
8+
#3 0x556e3dc9349f in read_a_msg /builddir/build/BUILD/rsync-3.2.3/io.c:1441
9+
#4 0x556e3dc93b23 in read_buf /builddir/build/BUILD/rsync-3.2.3/io.c:1853
10+
#5 0x556e3dc958d1 in read_ndx /builddir/build/BUILD/rsync-3.2.3/io.c:2241
11+
#6 0x556e3dc31316 in read_ndx_and_attrs /builddir/build/BUILD/rsync-3.2.3/rsync.c:330
12+
#7 0x556e3dc43f51 in recv_files /builddir/build/BUILD/rsync-3.2.3/receiver.c:548
13+
#8 0x556e3dc664b2 in do_recv /builddir/build/BUILD/rsync-3.2.3/main.c:1048
14+
#9 0x556e3dc66fc7 in do_server_recv /builddir/build/BUILD/rsync-3.2.3/main.c:1219
15+
#10 0x556e3dc66fc7 in start_server /builddir/build/BUILD/rsync-3.2.3/main.c:1253
16+
#11 0x556e3dc67418 in child_main /builddir/build/BUILD/rsync-3.2.3/main.c:1226
17+
#12 0x556e3dcca5f2 in local_child /builddir/build/BUILD/rsync-3.2.3/pipe.c:166
18+
#13 0x556e3dc0bb33 in do_cmd /builddir/build/BUILD/rsync-3.2.3/main.c:650
19+
#14 0x556e3dc0bb33 in start_client /builddir/build/BUILD/rsync-3.2.3/main.c:1576
20+
#15 0x556e3dc0bb33 in main /builddir/build/BUILD/rsync-3.2.3/main.c:1819
21+
#16 0x7fc94402950f in __libc_start_call_main (/lib64/libc.so.6+0x2950f)
22+
#17 0x7fc9440295c8 in __libc_start_main_alias_2 (/lib64/libc.so.6+0x295c8)
23+
#18 0x556e3dc0f324 in _start (/builddir/build/BUILD/rsync-3.2.3/rsync+0xbe324)
24+
25+
test.c:2:23: runtime error: load of null pointer of type 'char'
26+
#0 0x401147 in main /home/lukas/csdiff/tests/csgrep/test.c:2
27+
#1 0x7f7851249b49 in __libc_start_call_main (/lib64/libc.so.6+0x27b49) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
28+
#2 0x7f7851249c0a in __libc_start_main_alias_2 (/lib64/libc.so.6+0x27c0a) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
29+
#3 0x401064 in _start (/home/lukas/csdiff/tests/csgrep/a.out+0x401064) (BuildId: 687486336bec7797f956f83fcb24faef18f1365c)
30+

Diff for: tests/csgrep/0112-gcc-parser-ubsan-bt-stdout.txt

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Error: UBSAN_WARNING:
2+
byteorder.h:83:9: runtime error: load of misaligned address 0x556e3e877805 for type 'const uint32_t', which requires 4 byte alignment
3+
0x556e3e877805: note: pointer points here
4+
# b5 21 00 00 6c 00 00 07 ff 65 a0 b8 03 05 2f 74 65 78 74 0e 70 d6 f0 d2 4d 97 21 a4 81 00 00 a0
5+
# ^
6+
/builddir/build/BUILD/rsync-3.2.3/byteorder.h:83: note: IVALu() at 0x556e3dc9349f
7+
/builddir/build/BUILD/rsync-3.2.3/byteorder.h:124: note: IVAL() at 0x556e3dc9349f
8+
/builddir/build/BUILD/rsync-3.2.3/io.c:921: note: raw_read_int() at 0x556e3dc9349f
9+
/builddir/build/BUILD/rsync-3.2.3/io.c:1441: note: read_a_msg() at 0x556e3dc9349f
10+
/builddir/build/BUILD/rsync-3.2.3/io.c:1853: note: read_buf() at 0x556e3dc93b23
11+
/builddir/build/BUILD/rsync-3.2.3/io.c:2241: note: read_ndx() at 0x556e3dc958d1
12+
/builddir/build/BUILD/rsync-3.2.3/rsync.c:330: note: read_ndx_and_attrs() at 0x556e3dc31316
13+
/builddir/build/BUILD/rsync-3.2.3/receiver.c:548: note: recv_files() at 0x556e3dc43f51
14+
/builddir/build/BUILD/rsync-3.2.3/main.c:1048: note: do_recv() at 0x556e3dc664b2
15+
/builddir/build/BUILD/rsync-3.2.3/main.c:1219: note: do_server_recv() at 0x556e3dc66fc7
16+
/builddir/build/BUILD/rsync-3.2.3/main.c:1253: note: start_server() at 0x556e3dc66fc7
17+
/builddir/build/BUILD/rsync-3.2.3/main.c:1226: note: child_main() at 0x556e3dc67418
18+
/builddir/build/BUILD/rsync-3.2.3/pipe.c:166: note: local_child() at 0x556e3dcca5f2
19+
/builddir/build/BUILD/rsync-3.2.3/main.c:650: note: do_cmd() at 0x556e3dc0bb33
20+
/builddir/build/BUILD/rsync-3.2.3/main.c:1576: note: start_client() at 0x556e3dc0bb33
21+
/builddir/build/BUILD/rsync-3.2.3/main.c:1819: note: main() at 0x556e3dc0bb33
22+
/lib64/libc.so.6: note: __libc_start_call_main() at 0x7fc94402950f
23+
/lib64/libc.so.6: note: __libc_start_main_alias_2() at 0x7fc9440295c8
24+
/builddir/build/BUILD/rsync-3.2.3/rsync: note: _start() at 0x556e3dc0f324
25+
26+
Error: UBSAN_WARNING:
27+
test.c:2:23: runtime error: load of null pointer of type 'char'
28+
/home/lukas/csdiff/tests/csgrep/test.c:2: note: main() at 0x401147
29+
/lib64/libc.so.6: note: __libc_start_call_main() at 0x7f7851249b49
30+
/lib64/libc.so.6: note: __libc_start_main_alias_2() at 0x7f7851249c0a
31+
/home/lukas/csdiff/tests/csgrep/a.out: note: _start() at 0x401064

Diff for: tests/csgrep/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,5 @@ test_csgrep("0107-gcc-prepend-path" )
154154
test_csgrep("0108-sarif-empty-results" )
155155
test_csgrep("0109-shellcheck-sarif-cwe" )
156156
test_csgrep("0110-warning-rate-limit" )
157+
test_csgrep("0111-gcc-parser-ubsan-simple" )
158+
test_csgrep("0112-gcc-parser-ubsan-bt" )

0 commit comments

Comments
 (0)