|
Revision 4640:a115f3ac3b62, 1.2 kB
(checked in by Rocco Rutte <pdmef@…>, 2 years ago)
|
|
Avoid safe_free() usage and add security checks
Add checks to check_sec.sh for memory functions.
These include a check for use of safe_free() instead of FREE() and a
check whether FREE(&...) is used.
For the former, SAFE_FREE_CHECKED is to be used, for the latter
FREE_CHECKED to avoid messages from check_sec.sh
|
|
|
| Line | |
|---|
| 1 | #!/bin/sh -- |
|---|
| 2 | |
|---|
| 3 | # |
|---|
| 4 | # grep for some things which may look like security problems. |
|---|
| 5 | # |
|---|
| 6 | |
|---|
| 7 | TMPFILE="`mktemp check_sec.tmp.XXXXXX`" || exit 1 |
|---|
| 8 | |
|---|
| 9 | RV=0; |
|---|
| 10 | |
|---|
| 11 | do_check_files () |
|---|
| 12 | { |
|---|
| 13 | pattern="$1" ; shift |
|---|
| 14 | magic="$1" ; shift |
|---|
| 15 | msg="$1" ; shift |
|---|
| 16 | egrep -n "$pattern" "$@" | \ |
|---|
| 17 | grep -v '^[^ ]*:[^ ]*#' | \ |
|---|
| 18 | fgrep -v "$magic" > $TMPFILE |
|---|
| 19 | |
|---|
| 20 | test -s $TMPFILE && { |
|---|
| 21 | echo "$msg" ; |
|---|
| 22 | cat $TMPFILE; |
|---|
| 23 | rm -f $TMPFILE; |
|---|
| 24 | RV=1; |
|---|
| 25 | } |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | do_check () |
|---|
| 29 | { |
|---|
| 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 '\<(mutt_)?strcpy' __STRCPY_CHECKED__ "Alert: Unchecked strcpy calls." |
|---|
| 35 | do_check '\<strcat' __STRCAT_CHECKED__ "Alert: Unchecked strcat calls." |
|---|
| 36 | do_check '\<sprintf.*%s' __SPRINTF_CHECKED__ "Alert: Unchecked sprintf calls." |
|---|
| 37 | do_check '\<strncat' __STRNCAT_CHECKED__ "You probably meant safe_strcat here." |
|---|
| 38 | do_check '\<safe_free' __SAFE_FREE_CHECKED__ "You probably meant FREE here." |
|---|
| 39 | do_check '\<FREE[ ]?\([^&]' __FREE_CHECKED__ "You probably meant FREE(&...) here." |
|---|
| 40 | |
|---|
| 41 | # don't do this check on others' code. |
|---|
| 42 | do_check_files '\<(malloc|realloc|free|strdup)[ ]*\(' __MEM_CHECKED__ "Alert: Use of traditional memory management calls." \ |
|---|
| 43 | *.c imap/*.c |
|---|
| 44 | |
|---|
| 45 | rm -f $TMPFILE |
|---|
| 46 | exit $RV |
|---|