summaryrefslogtreecommitdiffstats
path: root/check_sec.sh
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>2001-01-08 23:09:30 +0000
committerThomas Roessler <roessler@does-not-exist.org>2001-01-08 23:09:30 +0000
commitcfdb67df5d5daa13ce785a2f4e87d8f12b673d71 (patch)
tree2d3d9b569a3392e85663155bd6dfcdc81a9e07e9 /check_sec.sh
parentd5a336245304225932d3b5d18f82336bebb01efe (diff)
Let check_sec.sh check for use of the unsafe malloc, realloc, free,
and strdup routines. While we are on it, plug some memory leaks and make some code understandable.
Diffstat (limited to 'check_sec.sh')
-rwxr-xr-xcheck_sec.sh24
1 files changed, 19 insertions, 5 deletions
diff --git a/check_sec.sh b/check_sec.sh
index 185752ac..988bb163 100755
--- a/check_sec.sh
+++ b/check_sec.sh
@@ -6,22 +6,36 @@
TMPFILE="`mktemp check_sec.tmp.XXXXXX`" || exit 1
-do_check ()
+do_check_files ()
{
- egrep -n "$1" *.c */*.c | fgrep -v $2 > $TMPFILE
+ pattern="$1" ; shift
+ magic="$1" ; shift
+ msg="$1" ; shift
+ egrep -n "$pattern" "$@" | \
+ grep -v '^[^ ]*:[^ ]*#' | \
+ fgrep -v "$magic" > $TMPFILE
+
test -s $TMPFILE && {
- echo "$3" ;
+ echo "$msg" ;
cat $TMPFILE;
+ rm -f $TMPFILE;
exit 1;
}
}
-
+do_check ()
+{
+ do_check_files "$1" "$2" "$3" *.c */*.c
+}
do_check '\<fopen.*'\"'.*w' __FOPEN_CHECKED__ "Alert: Unchecked fopen calls."
do_check '\<(mutt_)?strcpy' __STRCPY_CHECKED__ "Alert: Unchecked strcpy calls."
do_check '\<strcat' __STRCAT_CHECKED__ "Alert: Unchecked strcat calls."
-do_check 'sprintf.*%s' __SPRINTF_CHECKED__ "Alert: Unchecked sprintf calls."
+do_check '\<sprintf.*%s' __SPRINTF_CHECKED__ "Alert: Unchecked sprintf calls."
+
+# don't do this check on others' code.
+do_check_files '\<(malloc|realloc|free|strdup)[ ]*\(' __MEM_CHECKED__ "Alert: Use of traditional memory management calls." \
+ *.c imap/*.c
rm -f $TMPFILE
exit 0