cybersecurity · intermediate · ~15 min
Mechanise an audit checklist.
Given five boolean flags (1 = OK, 0 = fail), score the program. Each flag corresponds to one item:
f1 = environment scrubbed (clearenv called)f2 = fds 0/1/2 confirmed open at startf3 = uses geteuid for auth decisions, not getuidf4 = uses openat + O_NOFOLLOW for file accessf5 = does not call system/popenImplement int setuid_score(int f1, int f2, int f3, int f4, int f5)
returning the count of items passing (0..5).
Auditing setuid programs is rote — 5 items. Mechanising the score makes you fast.
5 booleans.
Count.
Sum 0/1 values.
int setuid_score(int f1, int f2, int f3, int f4, int f5) { /* TODO */ (void)f1; (void)f2; (void)f3; (void)f4; (void)f5; return 0; }
Treating any non-zero as 1 (we want strict 0/1).
All zero. All one. Any combination.
O(1).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.