cybersecurity · beginner · ~15 min · safe pentest lab

Flag a NOP sled over a threshold

Return a boolean verdict: is there a NOP run at least `threshold` long?

Challenge

Turn the measurement into an alert:

int has_nop_sled(const unsigned char *buf, size_t n, int threshold);

Return 1 if any run of consecutive 0x90 bytes has length >= threshold, else 0. Treat threshold<1 as 1.

Input format

buf, and a threshold (>=1).

Output format

1 if a sled >= threshold exists, else 0.

Constraints

threshold<1 is clamped to 1.

Starter code

#include <stddef.h>
/* 1 if buf contains a run of >= threshold consecutive 0x90 bytes (threshold clamped to >=1). */
int has_nop_sled(const unsigned char *buf, size_t n, int threshold){ (void)buf;(void)n;(void)threshold; return 0; }

Common mistakes

Off-by-one in the comparison (> vs >=); not clamping a non-positive threshold.

Edge cases to handle

Empty buffer returns 0; exact-threshold run returns 1.

Background lessons

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