Complexity is the enemy of security.
Typical errors: buffer overflow, race conditions, etc.
gets()
, strcpy()
, sprintf()
..access()
, stat()
other than fstat()
..Check declaration, should use malloc
:
char buf[1024]; // bad declaration
Not as easy as it sounds -- buffer sizes not always obvious
void buildmsg(char *dst, char *s, char *msg){
sprintf(dst, "Error: %s: %s\n", s, msg);
return;
}
security sensitive
programs.date
command$ date
Mon Nov 17 21:51:03 EST 2008
$ TZ=/usr/share/zoneinfo/Pacific/Guam date
Tue Nov 18 12:51:11 ChST 2008
$ TZ=/usr/share/zoneinfo/Pacific/Tahiti date
Mon Nov 17 16:51:20 TAHT 2008
BLIND TESTING
: in the case of timezone, it won't find the error.grep
for suspect functions.Call graph:
$ cflow env/*.c
main() <int main (int argc,char **argv) at env/env.c:55>:
setlocale()
getopt()
usage() <void usage (void) at env/env.c:94>:
fprintf()
exit()
strchr()
setenv()
execvp()
err()
printf()
exit()