retiring gets(3)

Peter Desnoyers desnoyer at Apple.COM
Tue Nov 15 03:25:32 AEST 1988


Perhaps I'm being naive, but wouldn't changing
  char buf[x];  gets( buf);
to
  char * buf;   buf = malloc( x);  gets( buf);
eliminate most (not all) of the security hole associated with gets()?
The problem seems to be not only the use of gets(), but the use of
temporary arrays on the stack to hold the output of dangerous
functions. If you keep the buffer off the stack you make it much more
difficult to exploit gets()'s unsafeness. (unless all you want to do
is make the program crash.)

				Peter Desnoyers



More information about the Comp.lang.c mailing list