Skip to content

Commit f600411

Browse files
committed
cslinker: do not abort on empty property in scan.ini
``` [...] >>> 2023-06-19 10:34:00 "cslinker --quiet --cwelist '/usr/share/csmock/cwe-map.csv' --inifile '/tmp/csmocklj8jvfjs/openshift-clients-4.7.0-202103251046.p0.git.3957.c4da68b.el8/scan.ini' '/tmp/csmocklj8jvfjs/openshift-clients-4.7.0-202103251046.p0.git.3957.c4da68b.el8/debug/uni-results'/* > '/tmp/csmocklj8jvfjs/openshift-clients-4.7.0-202103251046.p0.git.3957.c4da68b.el8/debug/scan-results-all.js'" terminate called after throwing an instance of 'boost::wrapexcept<boost::bad_lexical_cast>' what(): bad lexical cast: source type value could not be interpreted as target !!! 2023-06-19 10:34:00 fatal error: caught signal 6 ``` Closes: #132
1 parent 2373ab2 commit f600411

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

Diff for: src/lib/writer-json-common.cc

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ bool isNumber(const std::string &str)
3838
{
3939
static auto isDigit = [](unsigned char c){ return std::isdigit(c); };
4040

41+
if (str.empty())
42+
// an empty string cannot be parsed as a number
43+
return false;
44+
4145
return std::all_of(str.begin(), str.end(), isDigit);
4246
}
4347

Diff for: tests/cslinker/0003-ini-parser/runtest.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
set -e
3+
set -x
4+
5+
# run cslinker
6+
"${CSLINKER_BIN}" --inifile "${TEST_SRC_DIR}/scan.ini" <() > scan-results.json
7+
8+
# compare the results with the expected results
9+
diff -up "${TEST_SRC_DIR}/scan-results.json" "${PWD}/scan-results.json"

Diff for: tests/cslinker/0003-ini-parser/scan-results.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"scan": {
3+
"enabled-plugins": "",
4+
"exit-code": 0,
5+
"host": "f37",
6+
"known-false-positives": "/usr/share/csmock/known-false-positives.js",
7+
"mock-config": "rhel-8-rhaos-x86_64",
8+
"project-name": "openshift-clients-4.7.0-202103251046.p0.git.3957.c4da68b.el8",
9+
"store-results-to": "/tmp/openshift-clients-4.7.0-202103251046.p0.git.3957.c4da68b.el8.tar.xz",
10+
"time-created": "2023-06-19 10:27:13",
11+
"time-finished": "2023-06-19 10:34:00",
12+
"tool": "csmock",
13+
"tool-args": "'/usr/bin/csmock' '-r' 'rhel-8-rhaos-x86_64' '-f' 'openshift-clients-4.7.0-202103251046.p0.git.3957.c4da68b.el8.src.rpm'",
14+
"tool-version": "csmock-3.4.1.20230406.104621.gdb10285.internal-1.fc37"
15+
},
16+
"defects": []
17+
}

Diff for: tests/cslinker/0003-ini-parser/scan.ini

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[scan]
2+
tool = csmock
3+
tool-version = csmock-3.4.1.20230406.104621.gdb10285.internal-1.fc37
4+
tool-args = '/usr/bin/csmock' '-r' 'rhel-8-rhaos-x86_64' '-f' 'openshift-clients-4.7.0-202103251046.p0.git.3957.c4da68b.el8.src.rpm'
5+
host = f37
6+
store-results-to = /tmp/openshift-clients-4.7.0-202103251046.p0.git.3957.c4da68b.el8.tar.xz
7+
time-created = 2023-06-19 10:27:13
8+
enabled-plugins =
9+
mock-config = rhel-8-rhaos-x86_64
10+
project-name = openshift-clients-4.7.0-202103251046.p0.git.3957.c4da68b.el8
11+
known-false-positives = /usr/share/csmock/known-false-positives.js
12+
time-finished = 2023-06-19 10:34:00
13+
exit-code = 0
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -e
3+
set -x
4+
5+
# check whether we are invoked from the correct directory
6+
test -d ../../cslinker/0003-ini-parser/
7+
8+
# find cslinker BINARY
9+
export CSLINKER_BIN=../../../csdiff_build/src/cslinker
10+
test -x $CSLINKER_BIN
11+
CSLINKER_BIN=$(realpath $CSLINKER_BIN)
12+
13+
# run the test in the _source_ directory to overwrite the expected output
14+
TEST_SRC_DIR="$PWD" ./runtest.sh

0 commit comments

Comments
 (0)