diff --git a/src/lib/msg-filter.cc b/src/lib/msg-filter.cc index 3e84e13d..c1fd57d8 100644 --- a/src/lib/msg-filter.cc +++ b/src/lib/msg-filter.cc @@ -66,10 +66,10 @@ struct MsgFilter::Private { TSubstMap fileSubsts; const std::string strKrn = "^[a-zA-Z+]+"; - const RE reKrn = RE(strKrn); + const RE reKrn = RE(strKrn + /* convert el8_9 -> el8 */ "|_[0-9]+$"); const RE reDir = RE("^([^:]*/)"); const RE reFile = RE("[^/]+$"); - const RE rePath = RE("^(?:/builddir/build/BUILD/)?([^/]+/)(.*)(\\.[ly])?$"); + const RE rePath = RE("^(?:/builddir/build/BUILD/)?([^/]+)/(.*)(\\.[ly])?$"); const RE rePyBuild = RE("^((?:/builddir/build/BUILD/)?[^/]+/)build/lib/(.*)$"); const RE reTmpPath = RE("^(/var)?/tmp/(.*)$"); const RE reTmpCleaner = RE("(.*)"); @@ -263,6 +263,11 @@ std::string MsgFilter::filterPath(const std::string &origPath) const return tmpPath; } + // "/usr/src/kernels/4.18.0-552.el8.x86_64+debug/..." + // -> "/usr/src/kernels/VERSION-RELEASE+debug/..." + const RE reKrnUsrSrc("^(/usr/src/kernels/)[^/-]+-[^/-]+((?:\\+debug)?/.*)$"); + path = regexReplaceWrap(path, reKrnUsrSrc, "\\1VERSION-RELEASE\\2"); + boost::smatch sm; if (boost::regex_match(path, sm, d->rePyBuild)) { // %{_builddir}/build/lib/setuptools/glob.py -> @@ -274,12 +279,11 @@ std::string MsgFilter::filterPath(const std::string &origPath) const // no match return path; - std::string nvr (sm[/* NVR */ 1]); - std::string core(sm[/* core */ 2]); + const std::string nvr = sm[/* NVR */ 1]; + path = sm[/* core */ 2]; // try to kill the multiple version strings in paths (kernel, OpenLDAP, ...) - nvr.resize(nvr.size() - 1); - std::string ver(boost::regex_replace(nvr, d->reKrn, "")); + const std::string ver = boost::regex_replace(nvr, d->reKrn, ""); const std::string krnPattern = d->strKrn + ver + "[^/]*/"; #if DEBUG_SUBST > 2 @@ -289,15 +293,15 @@ std::string MsgFilter::filterPath(const std::string &origPath) const #endif const RE reKill(krnPattern); - core = boost::regex_replace(core, reKill, ""); + path = boost::regex_replace(path, reKill, ""); // quirk for Coverity inconsistency in handling bison-generated file names std::string suff(sm[/* Bison suffix */ 3]); if (!suff.empty()) - core += ".c"; + path += ".c"; #if DEBUG_SUBST - std::cerr << "filterPath: " << path << " -> " << core << "\n"; + std::cerr << "filterPath: " << origPath << " -> " << path << "\n"; #endif - return core; + return path; } diff --git a/tests/csdiff/CMakeLists.txt b/tests/csdiff/CMakeLists.txt index fe06e3b9..77b8cc2d 100644 --- a/tests/csdiff/CMakeLists.txt +++ b/tests/csdiff/CMakeLists.txt @@ -84,6 +84,8 @@ test_csdiff(diff-misc 16-cov-parser-key-event) test_csdiff(diff-misc 17-cov-parser-key-event) test_csdiff(diff-misc 18-cov-parser-key-event) test_csdiff(diff-misc 19-cov-parser-key-event) +test_csdiff(diff-misc 21-kernel-shell-code) +test_csdiff(diff-misc 22-kernel-zstream-path) test_csdiff(diff-misc 23-cov-parser-key-event) add_subdirectory(filter-file) diff --git a/tests/csdiff/diff-misc/21-kernel-shell-code-add-z.err b/tests/csdiff/diff-misc/21-kernel-shell-code-add-z.err new file mode 100644 index 00000000..e69de29b diff --git a/tests/csdiff/diff-misc/21-kernel-shell-code-add.err b/tests/csdiff/diff-misc/21-kernel-shell-code-add.err new file mode 100644 index 00000000..e69de29b diff --git a/tests/csdiff/diff-misc/21-kernel-shell-code-fix-z.err b/tests/csdiff/diff-misc/21-kernel-shell-code-fix-z.err new file mode 100644 index 00000000..e69de29b diff --git a/tests/csdiff/diff-misc/21-kernel-shell-code-fix.err b/tests/csdiff/diff-misc/21-kernel-shell-code-fix.err new file mode 100644 index 00000000..e69de29b diff --git a/tests/csdiff/diff-misc/21-kernel-shell-code-new.err b/tests/csdiff/diff-misc/21-kernel-shell-code-new.err new file mode 100644 index 00000000..09920729 --- /dev/null +++ b/tests/csdiff/diff-misc/21-kernel-shell-code-new.err @@ -0,0 +1,23 @@ +Error: SHELLCHECK_WARNING (CWE-398): +/usr/libexec/kselftests/drivers/net/netdevsim/ethtool-common.sh:31:8: error[SC1073]: Couldn't parse this test expression. Fix to allow more checks. +# 29| [ -z "$exp_fail" ] && cop="-ne" || cop="-eq" +# 30| +# 31|-> if [ $code $cop 0 ]; then +# 32| ((num_errors++)) +# 33| return + +Error: SHELLCHECK_WARNING (CWE-398): +/usr/src/kernels/4.18.0-552.el8.x86_64+debug/scripts/decode_stacktrace.sh:116:6: error[SC1073]: Couldn't parse this test expression. Fix to allow more checks. +# 114| +# 115| # Format timestamps with tabs +# 116|-> if [[ ${words[$i]} == \[ && ${words[$i+1]} == *\] ]]; then +# 117| unset words[$i] +# 118| words[$i+1]=$(printf "[%13s\n" "${words[$i+1]}") + +Error: SHELLCHECK_WARNING (CWE-398): +/usr/src/kernels/4.18.0-552.el8.x86_64/scripts/decode_stacktrace.sh:116:6: error[SC1073]: Couldn't parse this test expression. Fix to allow more checks. +# 114| +# 115| # Format timestamps with tabs +# 116|-> if [[ ${words[$i]} == \[ && ${words[$i+1]} == *\] ]]; then +# 117| unset words[$i] +# 118| words[$i+1]=$(printf "[%13s\n" "${words[$i+1]}") diff --git a/tests/csdiff/diff-misc/21-kernel-shell-code-old.err b/tests/csdiff/diff-misc/21-kernel-shell-code-old.err new file mode 100644 index 00000000..47832d8d --- /dev/null +++ b/tests/csdiff/diff-misc/21-kernel-shell-code-old.err @@ -0,0 +1,23 @@ +Error: SHELLCHECK_WARNING (CWE-398): +/usr/libexec/kselftests/drivers/net/netdevsim/ethtool-common.sh:31:8: error[SC1073]: Couldn't parse this test expression. Fix to allow more checks. +# 29| [ -z "$exp_fail" ] && cop="-ne" || cop="-eq" +# 30| +# 31|-> if [ $code $cop 0 ]; then +# 32| ((num_errors++)) +# 33| return + +Error: SHELLCHECK_WARNING (CWE-398): +/usr/src/kernels/4.18.0-513.5.1.el8.x86_64+debug/scripts/decode_stacktrace.sh:116:6: error[SC1073]: Couldn't parse this test expression. Fix to allow more checks. +# 114| +# 115| # Format timestamps with tabs +# 116|-> if [[ ${words[$i]} == \[ && ${words[$i+1]} == *\] ]]; then +# 117| unset words[$i] +# 118| words[$i+1]=$(printf "[%13s\n" "${words[$i+1]}") + +Error: SHELLCHECK_WARNING (CWE-398): +/usr/src/kernels/4.18.0-513.5.1.el8.x86_64/scripts/decode_stacktrace.sh:116:6: error[SC1073]: Couldn't parse this test expression. Fix to allow more checks. +# 114| +# 115| # Format timestamps with tabs +# 116|-> if [[ ${words[$i]} == \[ && ${words[$i+1]} == *\] ]]; then +# 117| unset words[$i] +# 118| words[$i+1]=$(printf "[%13s\n" "${words[$i+1]}") diff --git a/tests/csdiff/diff-misc/22-kernel-zstream-path-add-z.err b/tests/csdiff/diff-misc/22-kernel-zstream-path-add-z.err new file mode 100644 index 00000000..e69de29b diff --git a/tests/csdiff/diff-misc/22-kernel-zstream-path-add.err b/tests/csdiff/diff-misc/22-kernel-zstream-path-add.err new file mode 100644 index 00000000..e69de29b diff --git a/tests/csdiff/diff-misc/22-kernel-zstream-path-fix-z.err b/tests/csdiff/diff-misc/22-kernel-zstream-path-fix-z.err new file mode 100644 index 00000000..e69de29b diff --git a/tests/csdiff/diff-misc/22-kernel-zstream-path-fix.err b/tests/csdiff/diff-misc/22-kernel-zstream-path-fix.err new file mode 100644 index 00000000..e69de29b diff --git a/tests/csdiff/diff-misc/22-kernel-zstream-path-new.err b/tests/csdiff/diff-misc/22-kernel-zstream-path-new.err new file mode 100644 index 00000000..30898a8b --- /dev/null +++ b/tests/csdiff/diff-misc/22-kernel-zstream-path-new.err @@ -0,0 +1,11 @@ +Error: UNINIT (CWE-457): +kernel-4.18.0-552.el8/linux-4.18.0-552.el8.x86_64/arch/x86/crypto/chacha20_glue.c:71:2: var_decl: Declaring variable "walk" without initializer. +kernel-4.18.0-552.el8/linux-4.18.0-552.el8.x86_64/arch/x86/crypto/chacha20_glue.c:74:2: path: Condition "__cond", taking false branch. +kernel-4.18.0-552.el8/linux-4.18.0-552.el8.x86_64/arch/x86/crypto/chacha20_glue.c:77:2: path: Condition "req->cryptlen <= 64", taking false branch. +kernel-4.18.0-552.el8/linux-4.18.0-552.el8.x86_64/arch/x86/crypto/chacha20_glue.c:77:2: path: Condition "!may_use_simd()", taking false branch. +kernel-4.18.0-552.el8/linux-4.18.0-552.el8.x86_64/arch/x86/crypto/chacha20_glue.c:80:2: uninit_use_in_call: Using uninitialized value "walk.flags" when calling "skcipher_walk_virt". +# 78| return crypto_chacha20_crypt(req); +# 79| +# 80|-> err = skcipher_walk_virt(&walk, req, true); +# 81| +# 82| crypto_chacha20_init(state, ctx, walk.iv); diff --git a/tests/csdiff/diff-misc/22-kernel-zstream-path-old.err b/tests/csdiff/diff-misc/22-kernel-zstream-path-old.err new file mode 100644 index 00000000..1ad84b07 --- /dev/null +++ b/tests/csdiff/diff-misc/22-kernel-zstream-path-old.err @@ -0,0 +1,11 @@ +Error: UNINIT (CWE-457): +kernel-4.18.0-513.5.1.el8_9/linux-4.18.0-513.5.1.el8.x86_64/arch/x86/crypto/chacha20_glue.c:71: var_decl: Declaring variable "walk" without initializer. +kernel-4.18.0-513.5.1.el8_9/linux-4.18.0-513.5.1.el8.x86_64/arch/x86/crypto/chacha20_glue.c:74: path: Condition "__cond", taking false branch. +kernel-4.18.0-513.5.1.el8_9/linux-4.18.0-513.5.1.el8.x86_64/arch/x86/crypto/chacha20_glue.c:77: path: Condition "req->cryptlen <= 64", taking false branch. +kernel-4.18.0-513.5.1.el8_9/linux-4.18.0-513.5.1.el8.x86_64/arch/x86/crypto/chacha20_glue.c:77: path: Condition "!may_use_simd()", taking false branch. +kernel-4.18.0-513.5.1.el8_9/linux-4.18.0-513.5.1.el8.x86_64/arch/x86/crypto/chacha20_glue.c:80: uninit_use_in_call: Using uninitialized value "walk.flags" when calling "skcipher_walk_virt". +# 78| return crypto_chacha20_crypt(req); +# 79| +# 80|-> err = skcipher_walk_virt(&walk, req, true); +# 81| +# 82| crypto_chacha20_init(state, ctx, walk.iv); diff --git a/tests/csdiff/diff-misc/sync.sh b/tests/csdiff/diff-misc/sync.sh index 9b3a15d8..2c394d2d 100755 --- a/tests/csdiff/diff-misc/sync.sh +++ b/tests/csdiff/diff-misc/sync.sh @@ -2,13 +2,14 @@ set -x csdiff=$(realpath ../../../csdiff_build/src/csdiff) +csgrep=$(realpath ../../../csdiff_build/src/csgrep) test -x "$csdiff" || exit $? for old in *-old.err; do test=${old%-old.err} new=${test}-new.err for args in "" "-z"; do - $csdiff $args $old $new | csgrep > ${test}-add${args}.err - $csdiff $args $new $old | csgrep > ${test}-fix${args}.err + $csdiff $args $old $new | $csgrep > ${test}-add${args}.err + $csdiff $args $new $old | $csgrep > ${test}-fix${args}.err done done