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:
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.

Popular posts

Mirth: recover space when mirthdb grows out of control

From 0 to ZFS replication in 5m with syncoid

1/4/2000 to 1/4/2025: the beginning