P
Paul Sheer
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
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