Skip to content

Commit

Permalink
parser-json-sarif: initialize the imp flag
Browse files Browse the repository at this point in the history
... to 1 if `level` is `error`.  This is how `csgrep ---mode=sarif`
encodes the `imp` flag.  As a side effect, all findings from Snyk Code
with `level` set to `error` will be marked as important.  Nevertheless,
this is what `csmock-plugin-snyk` explicitly does already:
csutils/csmock#122

Resolves: https://issues.redhat.com/browse/OSH-754
Closes: #205
  • Loading branch information
kdudka committed Sep 9, 2024
1 parent f16db5a commit 9693a42
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/parser-json-sarif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,12 @@ bool SarifTreeDecoder::readNode(Defect *def)
// initialize the defect structure
*def = Defect(d->singleChecker);

// initialize the key event
// read "level" if available and propagate "error" to the "imp" flag
const auto level = valueOf<std::string>(defNode, "level", "warning");
if (level == "error")
def->imp = 1;

// initialize the key event
def->events.push_back(DefEvent(level));
DefEvent &keyEvent = def->events.back();

Expand Down
22 changes: 22 additions & 0 deletions tests/csgrep/0106-snyk-prepend-path-stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -193,6 +194,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -210,6 +212,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -227,6 +230,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -244,6 +248,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -261,6 +266,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -278,6 +284,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -295,6 +302,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -312,6 +320,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -329,6 +338,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -346,6 +356,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -363,6 +374,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -380,6 +392,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -397,6 +410,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -414,6 +428,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -431,6 +446,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -448,6 +464,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -465,6 +482,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -482,6 +500,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -499,6 +518,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 122,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand Down Expand Up @@ -771,6 +791,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 1325,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand All @@ -788,6 +809,7 @@
{
"checker": "SNYK_CODE_WARNING",
"cwe": 1325,
"imp": 1,
"tool": "snyk-code",
"key_event_idx": 0,
"events": [
Expand Down

0 comments on commit 9693a42

Please sign in to comment.