check_sec.sh 1.31 KB
Newer Older
1 2 3 4 5 6
#!/bin/sh --

#
# grep for some things which may look like security problems.
#

7 8
TMPFILE="`mktemp check_sec.tmp.XXXXXX`" || exit 1

9 10
RV=0;

11
do_check_files ()
12
{
13 14 15 16 17 18 19
	pattern="$1" ; shift
	magic="$1" ; shift
	msg="$1" ; shift
	egrep -n "$pattern" "$@"        	| \
		grep -v '^[^	 ]*:[^ 	]*#' 	| \
		fgrep -v "$magic" > $TMPFILE

20
	test -s $TMPFILE && {
21
		echo "$msg" ;
22
		cat $TMPFILE;
23
		rm -f $TMPFILE;
24
		RV=1;
25
	}
26 27
}

28 29
do_check ()
{
Thomas Roessler's avatar
Thomas Roessler committed
30
	do_check_files "$1" "$2" "$3" `find . -path ./intl -prune -o -name '*.c' -print`
31
}
32 33

do_check '\<fopen.*'\"'.*w' __FOPEN_CHECKED__ "Alert: Unchecked fopen calls."
34
do_check '\<fclose.*'\"'.*w' __FCLOSE_CHECKED__ "Alert: Unchecked fclose calls."
35
do_check '\<(mutt_)?strcpy' __STRCPY_CHECKED__ "Alert: Unchecked strcpy calls."
36
do_check '\<strcat' __STRCAT_CHECKED__ "Alert: Unchecked strcat calls."
37
do_check '\<sprintf.*%s' __SPRINTF_CHECKED__ "Alert: Unchecked sprintf calls."
38
do_check '\<strncat' __STRNCAT_CHECKED__ "You probably meant safe_strcat here."
39 40
do_check '\<safe_free' __SAFE_FREE_CHECKED__ "You probably meant FREE here."
do_check '\<FREE[ ]?\([^&]' __FREE_CHECKED__ "You probably meant FREE(&...) here."
41 42 43 44

# 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
45

46
rm -f $TMPFILE
47
exit $RV