Skip to content

Commit 758efde

Browse files
committed
gcc-parser: read CWE numbers from Cppcheck output if available
1 parent 4abf288 commit 758efde

File tree

5 files changed

+67
-2
lines changed

5 files changed

+67
-2
lines changed

gcc-parser.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class BasicGccParser {
368368
tokenizer_(&markerConverter_),
369369
fileName_(fileName),
370370
silent_(silent),
371-
reCppcheck_("^([A-Za-z_]+): (.*)$"),
371+
reCppcheck_("^([A-Za-z_]+)(?:\\(CWE-([0-9]+)\\))?: (.*)$"),
372372
reClang_("^clang.*$"),
373373
reProspector_(RE_EVENT_PROSPECTOR),
374374
reShellCheckMsg_("^.* \\[SC[0-9]+\\]$"),
@@ -432,7 +432,13 @@ bool BasicGccParser::digCppcheckEvt(Defect *pDef) {
432432
keyEvt.event += "[";
433433
keyEvt.event += sm[/* id */ 1];
434434
keyEvt.event += "]";
435-
keyEvt.msg = sm[/* msg */ 2];
435+
436+
// store CWE if available
437+
pDef->cwe = parse_int(sm[/* cwe */ 2]);
438+
439+
// this assignment invalidates sm!
440+
keyEvt.msg = sm[/* msg */ 3];
441+
436442
return true;
437443
}
438444

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ test_csgrep(csgrep "56-gcc-sparser-clang-error" )
176176
test_csgrep(csgrep "57-gcc-parser-gcc-analyzer-curl")
177177
test_csgrep(csgrep "58-csparser-gcc-analyzer-curl")
178178
test_csgrep(csgrep "59-json-parser-cov-v7-cwe" )
179+
test_csgrep(csgrep "60-gcc-parser-cppcheck-cwe" )
179180
test_csparser(csparser-5.8 00)
180181
test_csparser(csparser-5.8 01)
181182
test_csparser(csparser-5.8 02)

tests/csgrep/60-gcc-parser-cppcheck-cwe-args.txt

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/builddir/build/BUILD/curl-7.66.0/lib/ftp.c:2416: error: nullPointerArithmetic: Pointer addition with NULL pointer. <--[cppcheck]
2+
/builddir/build/BUILD/curl-7.66.0/lib/curl_ntlm_core.c:394: error: uninitvar(CWE-908): Uninitialized variable: ks <--[cppcheck]
3+
/builddir/build/BUILD/curl-7.66.0/lib/curl_ntlm_core.c:469: error: uninitvar(CWE-908): Uninitialized variable: ks <--[cppcheck]
4+
/builddir/build/BUILD/curl-7.66.0/lib/vtls/openssl.c: In function 'ossl_connect_step1': <--[gcc]
5+
/builddir/build/BUILD/curl-7.66.0/lib/vtls/openssl.c:2461:5: warning: 'SSLv3_client_method' is deprecated [-Wdeprecated-declarations] <--[gcc]
6+
2461 | req_method = SSLv3_client_method();
7+
| ^~~~~~~~~~
8+
In file included from /usr/include/openssl/opensslconf.h:42, <--[gcc]
9+
from /usr/include/openssl/e_os2.h:13, <--[gcc]
10+
from /usr/include/openssl/ssl.h:15, <--[gcc]
11+
from /builddir/build/BUILD/curl-7.66.0/lib/vtls/openssl.c:48: <--[gcc]
12+
/usr/include/openssl/ssl.h:1869:1: note: declared here <--[gcc]
13+
1869 | DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *SSLv3_client_method(void))
14+
| ^~~~~~~~~~~~~~~~~~
15+
/builddir/build/BUILD/curl-7.66.0/lib/vtls/openssl.c:2204:3: warning: Value stored to 'ossl_ssl_version_max' is never read <--[clang]
16+
ossl_ssl_version_max = 0;
17+
^ ~
18+
/builddir/build/BUILD/curl-7.66.0/lib/vtls/openssl.c:2204:3: note: Value stored to 'ossl_ssl_version_max' is never read <--[clang]
19+
ossl_ssl_version_max = 0;
20+
^ ~
21+
1 warning generated.
22+
gcc: warning: '-x c' after last input file has no effect
23+
g++: warning: '-x c' after last input file has no effect
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Error: CPPCHECK_WARNING:
2+
/builddir/build/BUILD/curl-7.66.0/lib/ftp.c:2416: error[nullPointerArithmetic]: Pointer addition with NULL pointer.
3+
4+
Error: CPPCHECK_WARNING (CWE-908):
5+
/builddir/build/BUILD/curl-7.66.0/lib/curl_ntlm_core.c:394: error[uninitvar]: Uninitialized variable: ks
6+
7+
Error: CPPCHECK_WARNING (CWE-908):
8+
/builddir/build/BUILD/curl-7.66.0/lib/curl_ntlm_core.c:469: error[uninitvar]: Uninitialized variable: ks
9+
10+
Error: COMPILER_WARNING:
11+
/builddir/build/BUILD/curl-7.66.0/lib/vtls/openssl.c: scope_hint: In function 'ossl_connect_step1'
12+
/builddir/build/BUILD/curl-7.66.0/lib/vtls/openssl.c:2461:5: warning: 'SSLv3_client_method' is deprecated [-Wdeprecated-declarations]
13+
# 2461 | req_method = SSLv3_client_method();
14+
# | ^~~~~~~~~~
15+
/usr/include/openssl/opensslconf.h:42: included_from: Included from here.
16+
/usr/include/openssl/e_os2.h:13: included_from: Included from here.
17+
/usr/include/openssl/ssl.h:15: included_from: Included from here.
18+
/builddir/build/BUILD/curl-7.66.0/lib/vtls/openssl.c:48: included_from: Included from here.
19+
/usr/include/openssl/ssl.h:1869:1: note: declared here
20+
# 1869 | DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *SSLv3_client_method(void))
21+
# | ^~~~~~~~~~~~~~~~~~
22+
23+
Error: CLANG_WARNING:
24+
/builddir/build/BUILD/curl-7.66.0/lib/vtls/openssl.c:2204:3: warning: Value stored to 'ossl_ssl_version_max' is never read
25+
# ossl_ssl_version_max = 0;
26+
# ^ ~
27+
/builddir/build/BUILD/curl-7.66.0/lib/vtls/openssl.c:2204:3: note: Value stored to 'ossl_ssl_version_max' is never read
28+
# ossl_ssl_version_max = 0;
29+
# ^ ~
30+
31+
Error: COMPILER_WARNING:
32+
gcc: warning: '-x c' after last input file has no effect
33+
34+
Error: COMPILER_WARNING:
35+
g++: warning: '-x c' after last input file has no effect

0 commit comments

Comments
 (0)