Skip to content

Commit bbe6142

Browse files
committed
csfilter: abstract out /build/lib in file paths
This is used by packaging of python modules. Reported-by: Miro Hrončok
1 parent abb3b57 commit bbe6142

File tree

5 files changed

+258
-0
lines changed

5 files changed

+258
-0
lines changed

src/csfilter.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct MsgFilter::Private {
6565
const RE reDir = RE("^([^:]*/)");
6666
const RE reFile = RE("[^/]+$");
6767
const RE rePath = RE("^(?:/builddir/build/BUILD/)?([^/]+/)(.*)(\\.[ly])?$");
68+
const RE rePyBuild = RE("^((?:/builddir/build/BUILD/)?[^/]+/)build/lib/(.*)$");
6869
const RE reTmpPath = RE("^(/var)?/tmp/(.*)$");
6970
const RE reTmpCleaner = RE("(.*)");
7071

@@ -197,6 +198,12 @@ std::string MsgFilter::filterPath(const std::string &origPath)
197198
}
198199

199200
boost::smatch sm;
201+
if (boost::regex_match(path, sm, d->rePyBuild)) {
202+
// %{_builddir}/build/lib/setuptools/glob.py ->
203+
// %{_builddir}/setuptools/glob.py
204+
path = sm[1] + sm[2];
205+
}
206+
200207
if (!boost::regex_match(path, sm, d->rePath))
201208
// no match
202209
return path;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--mode=json --remove-duplicates
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
{
2+
"scan": {
3+
"analyzer-version-clang": "11.1.0",
4+
"analyzer-version-coverity": "2020.12",
5+
"analyzer-version-cppcheck": "2.1",
6+
"analyzer-version-gcc": "11.0.0",
7+
"analyzer-version-gcc-analyzer": "11.0.0",
8+
"analyzer-version-shellcheck": "0.7.1",
9+
"cov-compilation-unit-count": 282,
10+
"cov-compilation-unit-ratio": 100,
11+
"cov-lines-processed": 70499,
12+
"cov-time-elapsed-analysis": "00:00:07",
13+
"exit-code": 0,
14+
"host": "cov04.lab.eng.brq.redhat.com",
15+
"known-false-positives": "/usr/share/csmock/known-false-positives.js",
16+
"mock-config": "rhel-9-alpha-x86_64",
17+
"project-name": "python-setuptools-53.0.0-1.el9",
18+
"store-results-to": "/tmp/tmpehhPYa/python-setuptools-53.0.0-1.el9.tar.xz",
19+
"time-created": "2021-02-23 06:30:38",
20+
"time-finished": "2021-02-23 06:32:19",
21+
"tool": "csmock",
22+
"tool-args": "'/bin/csmock' '-t' 'cppcheck,gcc,shellcheck,clang,coverity' '-r' 'rhel-9-alpha-x86_64' '-o' '/tmp/tmpehhPYa/python-setuptools-53.0.0-1.el9.tar.xz' '--cov-analyze-java' '--cov-analyze-opts=--security --concurrency' '--use-host-cppcheck' '--gcc-analyze' '--cov-use-instance' '/opt/cov-sa-2020.12' '/tmp/tmpehhPYa/python-setuptools-53.0.0-1.el9.src.rpm'",
23+
"tool-version": "csmock-2.7.0.20210216.090633.gd7fc8c2.internal-1.el7"
24+
},
25+
"defects": [
26+
{
27+
"checker": "COPY_PASTE_ERROR",
28+
"cwe": 398,
29+
"function": "_iglob",
30+
"language": "python",
31+
"key_event_idx": 1,
32+
"events": [
33+
{
34+
"file_name": "setuptools-53.0.0/build/lib/setuptools/glob.py",
35+
"line": 55,
36+
"event": "original",
37+
"message": "\"yield pathname\" looks like the original copy.",
38+
"verbosity_level": "1"
39+
},
40+
{
41+
"file_name": "setuptools-53.0.0/build/lib/setuptools/glob.py",
42+
"line": 59,
43+
"event": "copy_paste_error",
44+
"message": "\"pathname\" in \"yield pathname\" looks like a copy-paste error.",
45+
"verbosity_level": "0"
46+
},
47+
{
48+
"file_name": "setuptools-53.0.0/build/lib/setuptools/glob.py",
49+
"line": 59,
50+
"event": "remediation",
51+
"message": "Should it say \"dirname\" instead?",
52+
"verbosity_level": "1"
53+
},
54+
{
55+
"file_name": "",
56+
"line": 0,
57+
"event": "#",
58+
"message": " 57| # Patterns ending with a slash should match only directories",
59+
"verbosity_level": "1"
60+
},
61+
{
62+
"file_name": "",
63+
"line": 0,
64+
"event": "#",
65+
"message": " 58| if os.path.isdir(dirname):",
66+
"verbosity_level": "1"
67+
},
68+
{
69+
"file_name": "",
70+
"line": 0,
71+
"event": "#",
72+
"message": " 59|-> yield pathname",
73+
"verbosity_level": "1"
74+
},
75+
{
76+
"file_name": "",
77+
"line": 0,
78+
"event": "#",
79+
"message": " 60| return",
80+
"verbosity_level": "1"
81+
},
82+
{
83+
"file_name": "",
84+
"line": 0,
85+
"event": "#",
86+
"message": " 61| ",
87+
"verbosity_level": "1"
88+
}
89+
]
90+
},
91+
{
92+
"checker": "COPY_PASTE_ERROR",
93+
"cwe": 398,
94+
"function": "_iglob",
95+
"language": "python",
96+
"key_event_idx": 1,
97+
"events": [
98+
{
99+
"file_name": "setuptools-53.0.0/setuptools/glob.py",
100+
"line": 55,
101+
"event": "original",
102+
"message": "\"yield pathname\" looks like the original copy.",
103+
"verbosity_level": "1"
104+
},
105+
{
106+
"file_name": "setuptools-53.0.0/setuptools/glob.py",
107+
"line": 59,
108+
"event": "copy_paste_error",
109+
"message": "\"pathname\" in \"yield pathname\" looks like a copy-paste error.",
110+
"verbosity_level": "0"
111+
},
112+
{
113+
"file_name": "setuptools-53.0.0/setuptools/glob.py",
114+
"line": 59,
115+
"event": "remediation",
116+
"message": "Should it say \"dirname\" instead?",
117+
"verbosity_level": "1"
118+
},
119+
{
120+
"file_name": "",
121+
"line": 0,
122+
"event": "#",
123+
"message": " 57| # Patterns ending with a slash should match only directories",
124+
"verbosity_level": "1"
125+
},
126+
{
127+
"file_name": "",
128+
"line": 0,
129+
"event": "#",
130+
"message": " 58| if os.path.isdir(dirname):",
131+
"verbosity_level": "1"
132+
},
133+
{
134+
"file_name": "",
135+
"line": 0,
136+
"event": "#",
137+
"message": " 59|-> yield pathname",
138+
"verbosity_level": "1"
139+
},
140+
{
141+
"file_name": "",
142+
"line": 0,
143+
"event": "#",
144+
"message": " 60| return",
145+
"verbosity_level": "1"
146+
},
147+
{
148+
"file_name": "",
149+
"line": 0,
150+
"event": "#",
151+
"message": " 61| ",
152+
"verbosity_level": "1"
153+
}
154+
]
155+
}
156+
]
157+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"scan": {
3+
"analyzer-version-clang": "11.1.0",
4+
"analyzer-version-coverity": "2020.12",
5+
"analyzer-version-cppcheck": "2.1",
6+
"analyzer-version-gcc": "11.0.0",
7+
"analyzer-version-gcc-analyzer": "11.0.0",
8+
"analyzer-version-shellcheck": "0.7.1",
9+
"cov-compilation-unit-count": 282,
10+
"cov-compilation-unit-ratio": 100,
11+
"cov-lines-processed": 70499,
12+
"cov-time-elapsed-analysis": "00:00:07",
13+
"exit-code": 0,
14+
"host": "cov04.lab.eng.brq.redhat.com",
15+
"known-false-positives": "/usr/share/csmock/known-false-positives.js",
16+
"mock-config": "rhel-9-alpha-x86_64",
17+
"project-name": "python-setuptools-53.0.0-1.el9",
18+
"store-results-to": "/tmp/tmpehhPYa/python-setuptools-53.0.0-1.el9.tar.xz",
19+
"time-created": "2021-02-23 06:30:38",
20+
"time-finished": "2021-02-23 06:32:19",
21+
"tool": "csmock",
22+
"tool-args": "'/bin/csmock' '-t' 'cppcheck,gcc,shellcheck,clang,coverity' '-r' 'rhel-9-alpha-x86_64' '-o' '/tmp/tmpehhPYa/python-setuptools-53.0.0-1.el9.tar.xz' '--cov-analyze-java' '--cov-analyze-opts=--security --concurrency' '--use-host-cppcheck' '--gcc-analyze' '--cov-use-instance' '/opt/cov-sa-2020.12' '/tmp/tmpehhPYa/python-setuptools-53.0.0-1.el9.src.rpm'",
23+
"tool-version": "csmock-2.7.0.20210216.090633.gd7fc8c2.internal-1.el7"
24+
},
25+
"defects": [
26+
{
27+
"checker": "COPY_PASTE_ERROR",
28+
"cwe": 398,
29+
"function": "_iglob",
30+
"language": "python",
31+
"key_event_idx": 1,
32+
"events": [
33+
{
34+
"file_name": "setuptools-53.0.0/build/lib/setuptools/glob.py",
35+
"line": 55,
36+
"event": "original",
37+
"message": "\"yield pathname\" looks like the original copy.",
38+
"verbosity_level": "1"
39+
},
40+
{
41+
"file_name": "setuptools-53.0.0/build/lib/setuptools/glob.py",
42+
"line": 59,
43+
"event": "copy_paste_error",
44+
"message": "\"pathname\" in \"yield pathname\" looks like a copy-paste error.",
45+
"verbosity_level": "0"
46+
},
47+
{
48+
"file_name": "setuptools-53.0.0/build/lib/setuptools/glob.py",
49+
"line": 59,
50+
"event": "remediation",
51+
"message": "Should it say \"dirname\" instead?",
52+
"verbosity_level": "1"
53+
},
54+
{
55+
"file_name": "",
56+
"line": 0,
57+
"event": "#",
58+
"message": " 57| # Patterns ending with a slash should match only directories",
59+
"verbosity_level": "1"
60+
},
61+
{
62+
"file_name": "",
63+
"line": 0,
64+
"event": "#",
65+
"message": " 58| if os.path.isdir(dirname):",
66+
"verbosity_level": "1"
67+
},
68+
{
69+
"file_name": "",
70+
"line": 0,
71+
"event": "#",
72+
"message": " 59|-> yield pathname",
73+
"verbosity_level": "1"
74+
},
75+
{
76+
"file_name": "",
77+
"line": 0,
78+
"event": "#",
79+
"message": " 60| return",
80+
"verbosity_level": "1"
81+
},
82+
{
83+
"file_name": "",
84+
"line": 0,
85+
"event": "#",
86+
"message": " 61| ",
87+
"verbosity_level": "1"
88+
}
89+
]
90+
}
91+
]
92+
}

tests/csgrep/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,4 @@ test_csgrep("65-gcc-parser-clang-warn-suff" )
112112
test_csgrep("66-json-parser-valgrind-dedup" )
113113
test_csgrep("67-json-parser-valgrind-dedup" )
114114
test_csgrep("68-gcc-parser-cppcheck-iterator1" )
115+
test_csgrep("69-csfilter-python-build-path" )

0 commit comments

Comments
 (0)