Skip to content

Commit 33ed37d

Browse files
committed
parser-json-sarif: canonicalize paths from GCC SARIF
... so that we do not end up with paths like this: ``` usbutils-018/redhat-linux-build/../usbmisc.c ``` Related: openscanhub/known-false-positives#6 Related: openscanhub/known-false-positives#7 PR: #228
1 parent 64aa715 commit 33ed37d

File tree

5 files changed

+2402
-1
lines changed

5 files changed

+2402
-1
lines changed

src/lib/parser-json-sarif.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "regex.hh"
2424

2525
#include <boost/algorithm/string/predicate.hpp>
26+
#include <boost/filesystem.hpp>
2627

2728
struct SarifTreeDecoder::Private {
2829
void updateCweMap(const pt::ptree *driverNode);
@@ -360,7 +361,10 @@ static void expandRelativePaths(Defect *pDef, const std::string &pwd)
360361

361362
default:
362363
// prepend `pwd` to relative path
363-
fileName = pwd + fileName;
364+
boost::filesystem::path fullPath = pwd + fileName;
365+
366+
// convert "/a/b/../c" to "a/c"
367+
fileName = fullPath.lexically_normal().string();
364368
}
365369
}
366370
}

tests/csgrep/0133-sarif-gcc-pwd-args.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)