cybersecurity · beginner · ~15 min · safe pentest lab
Find the longest run of 0x90 (x86 NOP) — the signature of a NOP sled.
Classic stack-smashing shellcode is preceded by a NOP sled (a long run of 0x90) so an imprecise jump still lands in it. Implement:
int longest_nop_run(const unsigned char *buf, size_t n);
Return the length of the longest run of consecutive 0x90 bytes.
buf of n bytes.
Longest 0x90 run length.
n==0 returns 0.
#include <stddef.h>
/* Longest run of 0x90 (x86 NOP) bytes in buf. */
int longest_nop_run(const unsigned char *buf, size_t n){ (void)buf;(void)n; return 0; }
Not resetting the run on a non-NOP byte; missing the run that ends at the buffer's end (handled naturally if you track the max as you go).
Runs at the start/end count; a non-0x90 byte resets the run.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.