gcc c question
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Fri Jun 9 00:47:00 GMT 2000
> First I would like to know if this falls under a compiler specific
> dilemna or a programming situation that could lead to errors.
It's the latter, using gets has the potential of introducing
hard-to-find bugs, and may pose security risks.
> Why is it dangerous?
Because gets won't know how large the buffer is that you provide. If
it reads more data than your buffer is long, it will silently
overwrite the memory past the buffer (this is known as a
buffer-overrun).
If the buffer is an automatic variable (i.e. on the stack), you can
overwrite function return addresses etc. People have been using these
kinds of problems to break into computers: Simply find a
buffer-overrun bug in, say, the Web server, and arrange to put
carefully-designed bytes on the stack.
Since that started, a number of counter measures have been taken. One
of them is the linker warning you got, so people learn about the
problem and can correct their servers (which lead to lots of changes
in many programs since).
> What would be an alternate form of obtaining a character, real, or
> integer string?
You can safely use fgets; this expects the buffer length in addition.
Regards,
Martin
More information about the Gcc-help
mailing list