Skip to content

Commit f1b56b0

Browse files
committed
parser-json-sarif: attempt to read generic trace events
... produced by Snyk Code Related: https://issues.redhat.com/browse/OSH-654 Closes: csutils#199
1 parent 6cd12b1 commit f1b56b0

File tree

3 files changed

+35440
-618
lines changed

3 files changed

+35440
-618
lines changed

src/lib/parser-json-sarif.cc

+22-12
Original file line numberDiff line numberDiff line change
@@ -241,25 +241,28 @@ static void sarifReadCodeFlow(Defect *pDef, const pt::ptree &cf)
241241
for (const auto &item : *locs) {
242242
const pt::ptree &tfLoc = item.second;
243243

244-
const pt::ptree *kindList;
245-
if (!findChildOf(&kindList, tfLoc, "kinds") || kindList->empty())
246-
// kind of the event not specified
247-
continue;
248-
249-
// concatenate event name
250244
std::string evtName;
251-
for (const auto &kindItem : *kindList) {
252-
const pt::ptree &kind = kindItem.second;
253-
if (!evtName.empty())
254-
evtName += "_";
255-
evtName += kind.data();
245+
const pt::ptree *kindList;
246+
if (findChildOf(&kindList, tfLoc, "kinds")) {
247+
// calculate event name from the `kinds` list
248+
for (const auto &kindItem : *kindList) {
249+
const pt::ptree &kind = kindItem.second;
250+
if (!evtName.empty())
251+
evtName += "_";
252+
evtName += kind.data();
253+
}
256254
}
257255

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

262-
evt.verbosityLevel = valueOf<int>(tfLoc, "nestingLevel", 1);
260+
// read/infer verbosity level
261+
evt.verbosityLevel = valueOf<int>(tfLoc, "nestingLevel",
262+
(evt.event.empty())
263+
? /* trace */ 2
264+
: /* info */ 1);
265+
263266
if (!evt.verbosityLevel)
264267
// update key event
265268
keyEventIdx = events.size() - 1U;
@@ -271,6 +274,13 @@ static void sarifReadCodeFlow(Defect *pDef, const pt::ptree &cf)
271274

272275
sarifReadLocation(&evt, *loc);
273276
sarifReadMsg(&evt.msg, *loc);
277+
278+
if (evt.event.empty()) {
279+
// if no `kind` is given, assume a generic trace event
280+
evt.event = "path";
281+
if (evt.msg.empty())
282+
evt.msg = "generic trace event";
283+
}
274284
}
275285

276286
if (events.size() <= 1U)

0 commit comments

Comments
 (0)