Skip to content

Commit 515c73e

Browse files
authored
Fix #14006 (CI: upload cppcheck premium sarif results to github) (danmar#7662)
1 parent a2600d0 commit 515c73e

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

.github/workflows/cppcheck-premium.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on:
1818

1919
permissions:
2020
contents: read
21+
security-events: write
2122

2223
jobs:
2324

@@ -28,7 +29,8 @@ jobs:
2829
with:
2930
persist-credentials: false
3031

31-
- name: Download cppcheckpremium
32+
- name: Download cppcheckpremium release
33+
if: false
3234
run: |
3335
premium_version=${{ inputs.premium_version }}
3436
if [ -z $premium_version ]; then
@@ -41,6 +43,15 @@ jobs:
4143
tar xzf cppcheckpremium.tar.gz
4244
mv cppcheckpremium-$premium_version cppcheckpremium
4345
46+
- name: Download cppcheckpremium devdrop
47+
run: |
48+
wget https://files.cppchecksolutions.com/devdrop/cppcheckpremium-devdrop-20250713-amd64.tar.gz -O cppcheckpremium.tar.gz
49+
tar xzvf cppcheckpremium.tar.gz
50+
mv cppcheckpremium-devdrop-20250713 cppcheckpremium
51+
# Overwrite cppcheck binary
52+
make -j$(nproc) CXXFLAGS=-O2 MATCHCOMPILER=yes
53+
cp cppcheck cppcheckpremium/
54+
4455
- name: Generate a license file
4556
run: |
4657
echo cppcheck > cppcheck.lic
@@ -52,4 +63,20 @@ jobs:
5263
- name: Check
5364
run: |
5465
cppcheckpremium/premiumaddon --check-loc-license cppcheck.lic > cppcheck-premium-loc
55-
cppcheckpremium/cppcheck -j$(nproc) -D__GNUC__ -D__CPPCHECK__ --suppressions-list=cppcheckpremium-suppressions --platform=unix64 --enable=style --premium=misra-c++-2023 --premium=cert-c++-2016 --inline-suppr --error-exitcode=1 lib
66+
cppcheckpremium/cppcheck --premium=safety-off -j$(nproc) -D__GNUC__ -D__CPPCHECK__ --suppressions-list=cppcheckpremium-suppressions --platform=unix64 --enable=style --premium=misra-c++-2023 --premium=cert-c++-2016 --inline-suppr lib --error-exitcode=0 --output-format=sarif 2> results.sarif
67+
68+
- name: Cat results
69+
run: |
70+
#sed -i 's|"security-severity":.*||' results.sarif
71+
cat results.sarif
72+
73+
- uses: actions/upload-artifact@v4
74+
with:
75+
name: results
76+
path: results.sarif
77+
78+
- name: Upload report
79+
uses: github/codeql-action/upload-sarif@v3
80+
with:
81+
sarif_file: results.sarif
82+
category: cppcheckpremium

cli/cppcheckexecutor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ namespace {
109109
// rule.properties.precision, rule.properties.problem.severity
110110
picojson::object properties;
111111
properties["precision"] = picojson::value(sarifPrecision(finding));
112-
double securitySeverity = 0;
112+
const char* securitySeverity = nullptr;
113113
if (finding.severity == Severity::error && !ErrorLogger::isCriticalErrorId(finding.id))
114-
securitySeverity = 9.9; // We see undefined behavior
114+
securitySeverity = "9.9"; // We see undefined behavior
115115
//else if (finding.severity == Severity::warning)
116116
// securitySeverity = 5.1; // We see potential undefined behavior
117-
if (securitySeverity > 0.5) {
117+
if (securitySeverity) {
118118
properties["security-severity"] = picojson::value(securitySeverity);
119119
const picojson::array tags{picojson::value("security")};
120120
properties["tags"] = picojson::value(tags);
@@ -139,8 +139,8 @@ namespace {
139139
artifactLocation["uri"] = picojson::value(location.getfile(false));
140140
physicalLocation["artifactLocation"] = picojson::value(artifactLocation);
141141
picojson::object region;
142-
region["startLine"] = picojson::value(static_cast<int64_t>(location.line));
143-
region["startColumn"] = picojson::value(static_cast<int64_t>(location.column));
142+
region["startLine"] = picojson::value(static_cast<int64_t>(location.line < 1 ? 1 : location.line));
143+
region["startColumn"] = picojson::value(static_cast<int64_t>(location.column < 1 ? 1 : location.column));
144144
region["endLine"] = region["startLine"];
145145
region["endColumn"] = region["startColumn"];
146146
physicalLocation["region"] = picojson::value(region);

test/cli/helloworld_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def test_sarif():
373373
assert res['runs'][0]['results'][0]['ruleId'] == 'zerodiv'
374374
assert res['runs'][0]['tool']['driver']['rules'][0]['id'] == 'zerodiv'
375375
assert res['runs'][0]['tool']['driver']['rules'][0]['properties']['precision'] == 'high'
376-
assert res['runs'][0]['tool']['driver']['rules'][0]['properties']['security-severity'] > 9.5
376+
assert res['runs'][0]['tool']['driver']['rules'][0]['properties']['security-severity'] == '9.9'
377377
assert 'security' in res['runs'][0]['tool']['driver']['rules'][0]['properties']['tags']
378378
assert re.match(r'[0-9]+(.[0-9]+)+', res['runs'][0]['tool']['driver']['semanticVersion'])
379379
assert 'level' in res['runs'][0]['tool']['driver']['rules'][0]['defaultConfiguration'] # #13885

0 commit comments

Comments
 (0)