Tinkering with semgrep
A couple years ago I was introduced to
semgrep (together with defectdojo) but I never really paid much attention to this tool until recently I had an
itch to scratch.
The itch:
all (curl) network calls must always have an associated timeout.
This can be (easily) achieved with semgrep using the following rule:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rules: | |
- id: curl-reset-without-lowspeed-time | |
languages: | |
- c | |
- cpp | |
severity: ERROR | |
message: curl_easy_reset() called without setting CURLOPT_LOW_SPEED_TIME | |
patterns: | |
- pattern: curl_easy_reset($CURLHANDLE); | |
- pattern-not-inside: |- | |
curl_easy_reset($CURLHANDLE); | |
... | |
curl_easy_setopt($CURLHANDLE, CURLOPT_LOW_SPEED_TIME, $TIME); | |
metadata: | |
category: correctness |
Took me a bit of fiddling to find the right pattern incantation, but seems to work.
Link to rule in semgrep playground.
Link to rule in semgrep playground.