cybersecurity · intermediate · ~15 min
Detect path-traversal components.
Flag a path that contains a .. sequence — a basic path-traversal indicator that lets a path escape its intended directory.
Implement int has_dotdot(const char *path) that returns 1 if path contains the substring "..", and 0 otherwise.
path: a NUL-terminated path string the grader provides.Returns 1 if ".." appears anywhere in path, 0 otherwise.
has_dotdot("/var/www/../etc/passwd") -> 1
has_dotdot("/var/www/index.html") -> 0
.. returns 0.A NUL-terminated path string path.
1 if path contains the substring ".."; otherwise 0.
Substring test for "..".
#include <string.h>
int has_dotdot(const char *path) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.