cybersecurity · intermediate · ~15 min · safe pentest lab
Pinned-substring matching with adjacency checks.
Count the HIGH-severity entries in a mock CVE feed — triaging a feed line-by-line with a precise substring match is the fastest path from feed to alert.
Implement int count_high_severity(const char *json) that returns how many records contain the exact field "severity":"HIGH".
json: a NUL-terminated string of \n-separated mock JSON records, baked into the harness.Returns int: the count of records matching the field (>= 0), or 0 if json == NULL.
'{"severity":"HIGH"}\n{"severity":"LOW"}\n' -> 1
'{"severity":"HIGHEST"}\n' -> 0 (not closed by ")
'{"name":"HIGH"}\n' -> 0 (key is "name")
" — HIGHEST, HIGHER, etc. must not match."severity":"HIGH" followed by a closing ". Matching just HIGH is fooled by HIGHEST/HIGHWAY.Triaging a CVE feed line-by-line with a pinned substring sweep is the fastest path from feed → alert. The lesson is in being precise about what you match.
A NUL-terminated string of \n-separated mock JSON records.
Count (>= 0). 0 on NULL.
The full needle is "severity":"HIGH" followed by ". Match the closing quote.
int count_high_severity(const char *json) {
/* TODO */
(void)json;
return 0;
}
Trusting strstr("HIGH") alone. Forgetting to advance past the match — infinite loop. Counting "name":"HIGH" because the key wasn't pinned.
Trailing record without newline. Mixed-case (we only accept all-caps HIGH).
O(n) where n is the input length.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.