Related articles |
---|
C++ Compiler with a -Wwarn-use-of-strcpy or similar option?? psheer@WITHOUTicon.co.za (Paul Sheer) (2004-09-07) |
Re: C++ Compiler with a -Wwarn-use-of-strcpy or similar option?? christian.bau@cbau.freeserve.co.uk (Christian Bau) (2004-09-08) |
Re: C++ Compiler with a -Wwarn-use-of-strcpy or similar option?? kenrose@tfb.com (Ken Rose) (2004-09-13) |
Re: C++ Compiler with a -Wwarn-use-of-strcpy or similar option?? strohm@airmail.net (John R. Strohm) (2004-09-13) |
Re: C++ Compiler with a -Wwarn-use-of-strcpy or similar option?? psheer@icon.co.za (2004-09-14) |
From: | "Paul Sheer" <psheer@WITHOUTicon.co.za> |
Newsgroups: | comp.compilers,comp.lang.c++ |
Date: | 7 Sep 2004 23:49:19 -0400 |
Organization: | The South African Internet Exchange |
Keywords: | C, question |
Posted-Date: | 07 Sep 2004 23:49:19 EDT |
I need to automatically search and replace all fixed size
buffer strcpy's with strncpy's (or better yet, strlcpy's)
as a security and stability audit. The code base is large
and it is not feasable to manually perform these changes.
I would like perhaps a C++ parser that can automatically
detect use of a strcpy to a buffer of fixed size. For instance,
struct x {
char member[128];
}
...
struct x X;
...
strcpy (X.member, p); /* <-- should generate a warning here */
but
struct x {
char *member;
}
...
struct x X;
...
strcpy (X.member, p); /* <-- should NOT generate a warning */
(The second case is too complex to fix at this point.)
Is there any way of doing this? Our code is C++ (not C) and I
have, for example, looked at
http://codeworker.free.fr/ScriptsRepository.html
but this does not seem to provide an easy solution.
I am anticipating writing a script that can search and replace
"strcpy (x.member, p);" with "strlcpy (x.member, p, sizeof(x.member));"
provided the script can be guaranteed that the replacement is valid
(and I suppose only a full C++ parser would know if it is valid).
Can GCC be modified to give such a warning?
thanks
-paul
Return to the
comp.compilers page.
Search the
comp.compilers archives again.