cybersecurity · intermediate · ~15 min · safe pentest lab

Is it a terminator canary?

Recognise the terminator-canary design.

Challenge

Recognise a terminator canary — a canary whose low byte is 0x00 so that string functions stop before cleanly overwriting it.

Task

Implement int is_terminator_canary(unsigned long c) that returns 1 if the low byte of c is 0, and 0 otherwise.

Input

  • c: a candidate canary value (unsigned long).

Output

Returns 1 if (c & 0xFF) == 0, 0 otherwise.

Example

is_terminator_canary(0xdeadbe00)   ->   1   (low byte is 0)
is_terminator_canary(0xdeadbeef)   ->   0

Edge cases

  • Only the lowest byte matters; the upper bytes are ignored.

Input format

A candidate canary value c (unsigned long).

Output format

1 if the low byte of c is 0; otherwise 0.

Constraints

Test (c & 0xFF) == 0.

Starter code

int is_terminator_canary(unsigned long c) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.