From 3c764eb4bd0fe8969227df0d69ca4e2c31729558 Mon Sep 17 00:00:00 2001 From: jperez Date: Wed, 12 Jun 2024 16:47:34 +0200 Subject: [PATCH] msg-filter: abstract out numbers from error[too-many] findings Abstract out the number of occurrences and configured rate limit in `error[too-many]` findings. Resolves: https://issues.redhat.com/browse/OSH-496 Closes: https://github.com/csutils/csdiff/pull/188 --- src/lib/msg-filter.cc | 5 +++++ tests/csdiff/CMakeLists.txt | 1 + .../diff-misc/26-too-many-events-filter-add-z.err | 7 +++++++ .../diff-misc/26-too-many-events-filter-add.err | 7 +++++++ .../diff-misc/26-too-many-events-filter-fix-z.err | 0 .../diff-misc/26-too-many-events-filter-fix.err | 0 .../diff-misc/26-too-many-events-filter-new.err | 15 +++++++++++++++ .../diff-misc/26-too-many-events-filter-old.err | 7 +++++++ 8 files changed, 42 insertions(+) create mode 100644 tests/csdiff/diff-misc/26-too-many-events-filter-add-z.err create mode 100644 tests/csdiff/diff-misc/26-too-many-events-filter-add.err create mode 100644 tests/csdiff/diff-misc/26-too-many-events-filter-fix-z.err create mode 100644 tests/csdiff/diff-misc/26-too-many-events-filter-fix.err create mode 100644 tests/csdiff/diff-misc/26-too-many-events-filter-new.err create mode 100644 tests/csdiff/diff-misc/26-too-many-events-filter-old.err diff --git a/src/lib/msg-filter.cc b/src/lib/msg-filter.cc index 3cab49f7..9fa9b4de 100644 --- a/src/lib/msg-filter.cc +++ b/src/lib/msg-filter.cc @@ -78,6 +78,11 @@ MsgFilter::MsgFilter(): d(new Private) { d->addMsgFilter("", "[0-9][0-9]* out of [0-9][0-9]* times"); + + // abstract out the number of occurrences and rate limit in error[too-many] findings + d->addMsgFilter("", "^[0-9]+ (occurrences of warning\\[.*\\] exceeded the specified limit) [0-9]+$", + "NNNN \\1 NNNN"); + d->addMsgFilter("UNUSED_VALUE", "\\(instance [0-9]+\\)"); d->addMsgFilter("STRING_OVERFLOW", diff --git a/tests/csdiff/CMakeLists.txt b/tests/csdiff/CMakeLists.txt index f2425d4b..f6236c0b 100644 --- a/tests/csdiff/CMakeLists.txt +++ b/tests/csdiff/CMakeLists.txt @@ -90,5 +90,6 @@ test_csdiff(diff-misc 22-kernel-zstream-path) test_csdiff(diff-misc 23-cov-parser-key-event) test_csdiff(diff-misc 24-shellcheck-line-content) test_csdiff(diff-misc 25-llvm-17-path-filter) +test_csdiff(diff-misc 26-too-many-events-filter) add_subdirectory(filter-file) diff --git a/tests/csdiff/diff-misc/26-too-many-events-filter-add-z.err b/tests/csdiff/diff-misc/26-too-many-events-filter-add-z.err new file mode 100644 index 00000000..428a345c --- /dev/null +++ b/tests/csdiff/diff-misc/26-too-many-events-filter-add-z.err @@ -0,0 +1,7 @@ +Error: SNYK_CODE_WARNING (CWE-89): +sqlite-src-3260000/tool/speedtest8.c:219:11: error[cpp/Sqli]: Unsanitized input from a file flows into sqlite3_prepare_v2, where it is used in an SQL query. This may result in an SQL injection vulnerability. +# 217| nStmt++; +# 218| nByte += n; +# 219|-> prepareAndRun(db, &zSql[i], bQuiet); +# 220| } +# 221| zSql[j] = ';'; diff --git a/tests/csdiff/diff-misc/26-too-many-events-filter-add.err b/tests/csdiff/diff-misc/26-too-many-events-filter-add.err new file mode 100644 index 00000000..428a345c --- /dev/null +++ b/tests/csdiff/diff-misc/26-too-many-events-filter-add.err @@ -0,0 +1,7 @@ +Error: SNYK_CODE_WARNING (CWE-89): +sqlite-src-3260000/tool/speedtest8.c:219:11: error[cpp/Sqli]: Unsanitized input from a file flows into sqlite3_prepare_v2, where it is used in an SQL query. This may result in an SQL injection vulnerability. +# 217| nStmt++; +# 218| nByte += n; +# 219|-> prepareAndRun(db, &zSql[i], bQuiet); +# 220| } +# 221| zSql[j] = ';'; diff --git a/tests/csdiff/diff-misc/26-too-many-events-filter-fix-z.err b/tests/csdiff/diff-misc/26-too-many-events-filter-fix-z.err new file mode 100644 index 00000000..e69de29b diff --git a/tests/csdiff/diff-misc/26-too-many-events-filter-fix.err b/tests/csdiff/diff-misc/26-too-many-events-filter-fix.err new file mode 100644 index 00000000..e69de29b diff --git a/tests/csdiff/diff-misc/26-too-many-events-filter-new.err b/tests/csdiff/diff-misc/26-too-many-events-filter-new.err new file mode 100644 index 00000000..eaad3581 --- /dev/null +++ b/tests/csdiff/diff-misc/26-too-many-events-filter-new.err @@ -0,0 +1,15 @@ +Error: SNYK_CODE_WARNING (CWE-190): +: error[too-many]: 1573 occurrences of warning[cpp/IntegerOverflow] exceeded the specified limit 1024 +sqlite-src-3260000/tsrc/testfile3.c:1304:5: note: 573 occurrences of warning[cpp/IntegerOverflow] were discarded because of this + +Error: SNYK_CODE_WARNING (CWE-190): +: error[memleak]: 1573 occurrences of warning[cpp/memleak] exceeded the specified limit 1024 +sqlite-src-3260000/tsrc/testfile3.c:1304:5: note: 573 occurrences of warning[cpp/IntegerOverflow] were discarded because of this + +Error: SNYK_CODE_WARNING (CWE-89): +sqlite-src-3260000/tool/speedtest8.c:219:11: error[cpp/Sqli]: Unsanitized input from a file flows into sqlite3_prepare_v2, where it is used in an SQL query. This may result in an SQL injection vulnerability. +# 217| nStmt++; +# 218| nByte += n; +# 219|-> prepareAndRun(db, &zSql[i], bQuiet); +# 220| } +# 221| zSql[j] = ';'; diff --git a/tests/csdiff/diff-misc/26-too-many-events-filter-old.err b/tests/csdiff/diff-misc/26-too-many-events-filter-old.err new file mode 100644 index 00000000..e623aec1 --- /dev/null +++ b/tests/csdiff/diff-misc/26-too-many-events-filter-old.err @@ -0,0 +1,7 @@ +Error: SNYK_CODE_WARNING (CWE-190): +: error[too-many]: 1573 occurrences of warning[cpp/IntegerOverflow] exceeded the specified limit 1024 +sqlite-src-3260000/tsrc/fts3.c:1304:5: note: 573 occurrences of warning[cpp/IntegerOverflow] were discarded because of this + +Error: SNYK_CODE_WARNING (CWE-190): +: error[memleak]: 15173 occurrences of warning[cpp/memleak] exceeded the specified limit 102123 +sqlite-src-3260000/tsrc/testfile3.c:1304:5: note: 573 occurrences of warning[cpp/IntegerOverflow] were discarded because of this