Students uncover dozens of Unix software flaws (News.com)
Posted Dec 17, 2004 18:17 UTC (Fri) by
JoeBuck (subscriber, #2330)
In reply to:
Students uncover dozens of Unix software flaws (News.com) by pjdc
Parent article:
Students uncover dozens of Unix software flaws (News.com)
The strl* functions are not magic, though they can be useful in getting rid of one class of error (and replacing it with another, less severe, class of error: the silent truncation of long lines).
Reading a line into a fixed-sized buffer is the problem, and use of strl* functions to get rid of the buffer overrun is only a band-aid. You may think that you can assume that no valid line will be more than N characters, and later on break when you get N+1 characters. You can get subtle bugs because strings are truncated to different lengths in different places.
Read lines into dynamically-sized buffers instead, e.g. std::string for C++ programmers, appropriate library for C programmers. The GNU Readline library, for example, does not impose arbitrary limits on string length (as long as you have virtual memory).
(
Log in to post comments)