Skip to content

Fix #14006 (CI: use cppcheck sarif output in github) #7668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/selfcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,41 @@ jobs:
with:
name: Callgrind Output
path: ./callgrind.*

build_sarif_github:
# Perform selfcheck and upload results to github using sarif format
# Results are shown here: https://github.com/danmar/cppcheck/security/code-scanning
# Motivation:
# * Non-inline warnings are not suppressed, we will need to double check warnings using the github interface (this simplifies the release process)
# * Tests that github integration works

strategy:
fail-fast: false # Prefer quick result

runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Build Cppcheck
run: |
make CXXFLAGS=-O2 MATCOMPILER=yes -j$(nproc)

- name: Run Cppcheck
run: |
./cppcheck -D__CPPCHECK__ -D__GNUC__ -DCHECK_INTERNAL -DHAVE_RULES --std=c++11 --library=cppcheck-lib --library=qt --enable=style --inconclusive --inline-suppr cli gui/*.cpp lib --output-format=sarif 2> results.sarif

- name: Results
run: |
cat results.sarif

- uses: actions/upload-artifact@v4
with:
name: results
path: results.sarif

- uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
7 changes: 4 additions & 3 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ namespace {
//else if (finding.severity == Severity::warning)
// securitySeverity = 5.1; // We see potential undefined behavior
if (securitySeverity > 0.5) {
properties["security-severity"] = picojson::value(securitySeverity);
// skipped: "security-severity" caused error when uploading to github
// properties["security-severity"] = picojson::value(securitySeverity);
const picojson::array tags{picojson::value("security")};
properties["tags"] = picojson::value(tags);
}
Expand All @@ -139,8 +140,8 @@ namespace {
artifactLocation["uri"] = picojson::value(location.getfile(false));
physicalLocation["artifactLocation"] = picojson::value(artifactLocation);
picojson::object region;
region["startLine"] = picojson::value(static_cast<int64_t>(location.line));
region["startColumn"] = picojson::value(static_cast<int64_t>(location.column));
region["startLine"] = picojson::value(static_cast<int64_t>(location.line < 1 ? 1 : location.line));
region["startColumn"] = picojson::value(static_cast<int64_t>(location.column < 1 ? 1 : location.column));
region["endLine"] = region["startLine"];
region["endColumn"] = region["startColumn"];
physicalLocation["region"] = picojson::value(region);
Expand Down
3 changes: 2 additions & 1 deletion test/cli/helloworld_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ def test_sarif():
assert res['runs'][0]['results'][0]['ruleId'] == 'zerodiv'
assert res['runs'][0]['tool']['driver']['rules'][0]['id'] == 'zerodiv'
assert res['runs'][0]['tool']['driver']['rules'][0]['properties']['precision'] == 'high'
assert res['runs'][0]['tool']['driver']['rules'][0]['properties']['security-severity'] > 9.5
# github does not seem to handle "security-severity" well so it's not added
#assert res['runs'][0]['tool']['driver']['rules'][0]['properties']['security-severity'] > 9.5
assert 'security' in res['runs'][0]['tool']['driver']['rules'][0]['properties']['tags']
assert re.match(r'[0-9]+(.[0-9]+)+', res['runs'][0]['tool']['driver']['semanticVersion'])
assert 'level' in res['runs'][0]['tool']['driver']['rules'][0]['defaultConfiguration'] # #13885
Expand Down