~/ learn/ comp-400/ cards/ Software Security and Buffer Overflow
1 of 44

The classic unbounded read: `gets()` into a fixed array

The classic unbounded read: `gets()` into a fixed array

Answer

void read_tag(void) { char buf[8]; gets(buf); /* no size argument exists */ printf("tag: %s\n", buf); }

There is no way to make this call safe, because `gets()` takes no length. It reads until a newline or end of file and writes every byte into `buf`, whatever the caller intended. The bound would have to come from the caller, and there is nowhere to put it.

Stallings & Brown 5e ch10 §10.1–10.2

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/260bdb15-27d5-4a79-9d05-fedd638e3d32/flashcard utf-8 LF