networking · intermediate · ~20 min
Strict header-parsing pattern with name validation.
A Cookie header is a single line: name1=value1; name2=value2; name3=value3.
Implement int find_cookie(const char *header, const char *name, char *out_value, int cap).
;.name exactly (case-sensitive).out_value, NUL-terminated.Reject (return 0) if the requested name contains any of: =, ;, \r, \n, space.
Every web server, every WAF, every analytics tag needs to read Cookie headers. Doing it strictly catches malformed cookies that smuggle attacks.
Header string + cookie name + output buffer.
0/1 + value.
Strict — no permissive whitespace inside name.
int find_cookie(const char *header, const char *name, char *out_value, int cap) { /* TODO */ (void)header; (void)name; (void)out_value; (void)cap; return 0; }
Using strstr — matches bar=x inside foobar=x. Use word-boundary matching.
Empty header. Cookie with empty value (name=;). Multiple instances (use first).
O(strlen).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.