Skip to content

Commit

Permalink
parser-json-sarif: attempt to read generic trace events
Browse files Browse the repository at this point in the history
... produced by Snyk Code

Related: https://issues.redhat.com/browse/OSH-654
Closes: #199
  • Loading branch information
kdudka committed Dec 12, 2024
1 parent 703c2f5 commit 4c0ae30
Show file tree
Hide file tree
Showing 3 changed files with 35,468 additions and 646 deletions.
34 changes: 22 additions & 12 deletions src/lib/parser-json-sarif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,25 +270,28 @@ static void sarifReadCodeFlow(Defect *pDef, const pt::ptree &cf)
for (const auto &item : *locs) {
const pt::ptree &tfLoc = item.second;

const pt::ptree *kindList;
if (!findChildOf(&kindList, tfLoc, "kinds") || kindList->empty())
// kind of the event not specified
continue;

// concatenate event name
std::string evtName;
for (const auto &kindItem : *kindList) {
const pt::ptree &kind = kindItem.second;
if (!evtName.empty())
evtName += "_";
evtName += kind.data();
const pt::ptree *kindList;
if (findChildOf(&kindList, tfLoc, "kinds")) {
// calculate event name from the `kinds` list
for (const auto &kindItem : *kindList) {
const pt::ptree &kind = kindItem.second;
if (!evtName.empty())
evtName += "_";
evtName += kind.data();
}
}

// append a new event of the specified kind
events.push_back(DefEvent(evtName));
DefEvent &evt = events.back();

evt.verbosityLevel = valueOf<int>(tfLoc, "nestingLevel", 1);
// read/infer verbosity level
evt.verbosityLevel = valueOf<int>(tfLoc, "nestingLevel",
(evt.event.empty())
? /* trace */ 2
: /* info */ 1);

if (!evt.verbosityLevel)
// update key event
keyEventIdx = events.size() - 1U;
Expand All @@ -300,6 +303,13 @@ static void sarifReadCodeFlow(Defect *pDef, const pt::ptree &cf)

sarifReadLocation(&evt, *loc);
sarifReadMsg(&evt.msg, *loc);

if (evt.event.empty()) {
// if no `kind` is given, assume a generic trace event
evt.event = "path";
if (evt.msg.empty())
evt.msg = "generic trace event";
}
}

if (events.size() <= 1U)
Expand Down
Loading

0 comments on commit 4c0ae30

Please sign in to comment.