cybersecurity · intermediate · ~15 min · safe pentest lab
Practise in-place string editing without leaking original data.
Scrub secret values out of a log line in place, so cleartext credentials never reach the log file.
Implement void redact_secrets(char *line) that edits line in place, replacing each secret value with ***:
password= (everything up to the next space or end of line), andtoken= (same: up to the next space or end of line).The key text (password= / token=) stays; only the value is replaced.
line: a NUL-terminated, mutable log line the grader provides. Its buffer is large enough to hold the redacted result, so you may shift characters as needed. At most one password= and one token= appear.No return value. line is modified in place to contain the redacted text.
"user=alice password=hunter2 token=abc123" -> "user=alice password=*** token=***"
"no secrets here" -> "no secrets here" (unchanged)
"password=" -> "password=***" (empty value)
password= at end of line): still becomes password=***.A NUL-terminated mutable log line; buffer is large enough for the result.
No return; line is edited in place with each secret value replaced by ***.
Edit in place; keep the key, replace only the value up to the next space or end.
#include <string.h>
void redact_secrets(char *line) {
/* TODO */
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.