strcpy -> strlcpy?

Matthew Dillon dillon at apollo.backplane.com
Tue Jan 4 16:18:26 PST 2005


:It was primarily done in OpenBSD to avoid introducing new bugs.  If I
:remember right, when we did the complete tree sweep, it caught around 10
:bugs or so in the conversions.  More in ports after doing a bulk build.
:I wouldn't bother with it if you aren't planning to do a similar mass
:conversion to strlcpy-style functions.
:
:Note that the patch does other things as well; it detects incorrect use of
:static buffers if the buffer size specified is larger than the actual
:buffer.  This has found around 60-70 bugs, mainly in the ports tree (a lot
:of them are sscanf string size specifiers which are off-by-one).
:
:Doing more complicated analyses is a pain in gcc though; I started hacking
:on some stuff using CIL by George Necula at Berkeley, which makes static
:analysis of real-world C much, much easier.
:
:-- 
:Anil Madhavapeddy                                 http://anil.recoil.org

    It sounds like a better approach to detecting these sorts of
    bugs would be to have a separate code parser and analysis tool.  C
    is actually very easy to parse (having written a C compiler I can
    say that with assurance), and even not all that hard to analyze. 
    The hard part is producing the assembly/other output.  I'll bet it
    would be easier then trying to build it directly into the GCC
    framework.

					-Matt
					Matthew Dillon 
					<dillon at xxxxxxxxxxxxx>





More information about the Kernel mailing list