cybersecurity · intermediate · ~15 min · safe pentest lab
Pull the path out of a request line.
Pull the path out of an HTTP request line — the middle token of METHOD PATH VERSION — into a bounded buffer.
Implement int request_path(const char *line, char *out, int outsz) that copies the second space-separated token (the path) of line into out, NUL-terminates it, and returns its length. Return -1 if line doesn't contain at least two spaces.
line: a NUL-terminated request line the grader provides (e.g. "GET /admin/login HTTP/1.1").out: the destination buffer.outsz: the size of out in bytes.Returns the path length on success (with out holding the path), or -1 if the line is malformed (fewer than two spaces).
request_path("GET /admin/login HTTP/1.1", out, 64) -> 12, out = "/admin/login"
request_path("GET", out, 64) -> -1 (no path token)
outsz - 1, copy what fits and NUL-terminate.A request line, a destination out, and its size outsz.
The path length with out set; or -1 if line lacks two spaces.
Copy the token between the first two spaces; NUL-terminate; -1 on malformed line.
#include <string.h>
int request_path(const char *line, char *out, int outsz) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.