26
26
27
27
struct SarifTreeDecoder ::Private {
28
28
void updateCweMap (const pt::ptree *driverNode);
29
+ void readToolInfo (TScanProps *pScanProps, const pt::ptree *toolNode);
29
30
30
31
std::string singleChecker = " UNKNOWN_SARIF_WARNING" ;
31
32
const RE reCwe = RE(" ^CWE-([0-9]+)$" );
@@ -80,35 +81,15 @@ void SarifTreeDecoder::Private::updateCweMap(const pt::ptree *driverNode)
80
81
}
81
82
}
82
83
83
- void SarifTreeDecoder::readScanProps (
84
- TScanProps *pDst ,
85
- const pt::ptree *root )
84
+ void SarifTreeDecoder::Private::readToolInfo (
85
+ TScanProps *pScanProps ,
86
+ const pt::ptree *toolNode )
86
87
{
87
- // read external properties if available
88
- const pt::ptree *iep;
89
- if (findChildOf (&iep, *root, " inlineExternalProperties" )
90
- && (1U == iep->size ()))
91
- {
92
- const pt::ptree *props;
93
- if (findChildOf (&props, iep->begin ()->second , " externalizedProperties" ))
94
- for (const pt::ptree::value_type &item : *props)
95
- (*pDst)[item.first ] = item.second .data ();
96
- }
97
-
98
- // check that we have exactly one run
99
- const pt::ptree *runs;
100
- if (!findChildOf (&runs, *root, " runs" ) || (1U != runs->size ()))
101
- return ;
102
-
103
- // check which tool was used for the run
104
- const pt::ptree *toolNode;
105
- if (!findChildOf (&toolNode, runs->begin ()->second , " tool" ))
106
- return ;
107
88
const pt::ptree *driverNode;
108
89
if (!findChildOf (&driverNode, *toolNode, " driver" ))
109
90
return ;
110
91
111
- d ->updateCweMap (driverNode);
92
+ this ->updateCweMap (driverNode);
112
93
113
94
const auto name = valueOf<std::string>(*driverNode, " name" );
114
95
auto version = valueOf<std::string>(*driverNode, " version" );
@@ -117,36 +98,66 @@ void SarifTreeDecoder::readScanProps(
117
98
118
99
if (name == " SnykCode" ) {
119
100
// Snyk Code detected!
120
- d ->singleChecker = " SNYK_CODE_WARNING" ;
101
+ this ->singleChecker = " SNYK_CODE_WARNING" ;
121
102
122
103
if (!version.empty ())
123
104
// record tool version of Snyk Code
124
- (*pDst )[" analyzer-version-snyk-code" ] = std::move (version);
105
+ (*pScanProps )[" analyzer-version-snyk-code" ] = std::move (version);
125
106
}
126
107
else if (name == " gitleaks" ) {
127
108
// gitleaks
128
- d ->singleChecker = " GITLEAKS_WARNING" ;
109
+ this ->singleChecker = " GITLEAKS_WARNING" ;
129
110
130
111
if (!version.empty ())
131
- (*pDst )[" analyzer-version-gitleaks" ] = std::move (version);
112
+ (*pScanProps )[" analyzer-version-gitleaks" ] = std::move (version);
132
113
}
133
114
else if (name == " Semgrep OSS" ) {
134
115
// semgrep
135
- d ->singleChecker = " SEMGREP_WARNING" ;
116
+ this ->singleChecker = " SEMGREP_WARNING" ;
136
117
137
118
if (!version.empty ())
138
- (*pDst )[" analyzer-version-semgrep" ] = std::move (version);
119
+ (*pScanProps )[" analyzer-version-semgrep" ] = std::move (version);
139
120
}
140
121
else if (boost::starts_with (name, " GNU C" )) {
141
122
// GCC
142
- d ->singleChecker = " COMPILER_WARNING" ;
123
+ this ->singleChecker = " COMPILER_WARNING" ;
143
124
144
125
boost::smatch sm;
145
- if (boost::regex_match (version, sm, d ->reVersion ))
146
- (*pDst )[" analyzer-version-gcc" ] = sm[/* version */ 1 ];
126
+ if (boost::regex_match (version, sm, this ->reVersion ))
127
+ (*pScanProps )[" analyzer-version-gcc" ] = sm[/* version */ 1 ];
147
128
}
148
129
}
149
130
131
+ void SarifTreeDecoder::readScanProps (
132
+ TScanProps *pDst,
133
+ const pt::ptree *root)
134
+ {
135
+ // read external properties if available
136
+ const pt::ptree *iep;
137
+ if (findChildOf (&iep, *root, " inlineExternalProperties" )
138
+ && (1U == iep->size ()))
139
+ {
140
+ const pt::ptree *props;
141
+ if (findChildOf (&props, iep->begin ()->second , " externalizedProperties" ))
142
+ for (const pt::ptree::value_type &item : *props)
143
+ (*pDst)[item.first ] = item.second .data ();
144
+ }
145
+
146
+ // check that we have exactly one run
147
+ const pt::ptree *runs;
148
+ if (!findChildOf (&runs, *root, " runs" )
149
+ || /* TODO: warn bout unsupported format */ (1U != runs->size ()))
150
+ return ;
151
+
152
+ // jump to the only run
153
+ const pt::ptree &run0 = runs->begin ()->second ;
154
+
155
+ // check which tool was used for the run
156
+ const pt::ptree *toolNode;
157
+ if (findChildOf (&toolNode, run0, " tool" ))
158
+ d->readToolInfo (pDst, toolNode);
159
+ }
160
+
150
161
void SarifTreeDecoder::readRoot (const pt::ptree *runs)
151
162
{
152
163
if (1U != runs->size ())
0 commit comments