4 ms·
> A well-known example is gets[1] which is impossible to use without introducing a buffer overflow. Actually, it is possible to use gets() safely, under a suff
by cesarb 6y ago
> A well-known example is gets[1] which is impossible to use without introducing a buffer overflow.
Actually, it is possible to use gets() safely, under a sufficiently contrived set of circumstances. Since it reads from stdin, you just have to make sure that stdin reads from a pipe which has its write end under the control of the same process, and be careful to only ever write a limited amount of data to that pipe, smaller than the buffer of any gets() call in the process.