retiring gets(3)

Geoff Collyer geoff at utstat.uucp
Tue Nov 15 08:08:42 AEST 1988


> From: gwyn at smoke.BRL.MIL (Doug Gwyn )
> 
> Bullshit.  When I use gets() I use it safely.

Okay, Doug, let's take this again from the top.  I'll use simple words
and try to make myself utterly clear, and I won't even abuse your
ancestry or swear at you, which I think is awfully polite of me, under
the circumstances.

To be proven: gets(3) should be abolished.

Any program which uses gets(3) can be corrupted by giving it a
long-enough input line.  There is no protection possible against such an
attack, other than sh's trick of making the gets buffer the last object
in the data segment, catching the resulting SIGSEGV signal, growing the
data segment and returning from the signal catcher, and this is
certainly not portable to Cray-1s and Sun-3s, for example.  gets is
probably unique among C library functions because it cannot be used
safely, no matter how hard you wish or how hard you work.  Thus there
seems little point (aside from writing unsafe programs) in continuing to
support gets in standards and C libraries.  QED
-- 
Geoff Collyer	utzoo!utstat!geoff, geoff at utstat.toronto.edu



More information about the Comp.lang.c mailing list