| 1 | #! /bin/sh |
| 2 | # |
| 3 | # Test for buffer overflow |
| 4 | # |
| 5 | LOG=`pwd`/test-log |
| 6 | echo ' *** starting ' $0 >>$LOG |
| 7 | . ${srcdir}/commonfuncs |
| 8 | pwd=`pwd` |
| 9 | tmprc="$pwd/../src/.namazurc" |
| 10 | echo "Index $pwd/idx19" > $tmprc |
| 11 | duprcs |
| 12 | |
| 13 | # To make messages English |
| 14 | unset LANG; export LANG |
| 15 | LANGUAGE=C; export LANGUAGE |
| 16 | LC_ALL=C; export LC_ALL |
| 17 | unset LC_MESSAGES; export LC_MESSAGES |
| 18 | unset LC_CTYPE; export LC_CTYPE |
| 19 | |
| 20 | SCRIPT_NAME='namazu.cgi' |
| 21 | export SCRIPT_NAME |
| 22 | |
| 23 | # long cgi paramater (should be chopped by QUERY_MAX) |
| 24 | QUERY_STRING='query='`perl -e 'print "x" x 2048'` |
| 25 | export QUERY_STRING |
| 26 | cd ../src |
| 27 | |
| 28 | RESULTS=`./namazu.cgi 2>> $LOG | grep -i 'too long' | wc -l` |
| 29 | test $RESULTS -ne 1 && exit 1 |
| 30 | |
| 31 | QUERY_STRING='query=+'`perl -e 'print "x" x 2048'`':foobar' |
| 32 | export QUERY_STRING |
| 33 | RESULTS=`./namazu.cgi 2>> $LOG | grep -i 'too long' | wc -l` |
| 34 | test $RESULTS -ne 1 && exit 1 |
| 35 | |
| 36 | QUERY_STRING='query=/'`perl -e 'print "x" x 2048'`'/' |
| 37 | export QUERY_STRING |
| 38 | RESULTS=`./namazu.cgi 2>> $LOG | grep -i 'too long' | wc -l` |
| 39 | test $RESULTS -ne 1 && exit 1 |
| 40 | |
| 41 | # long SCRIPT_NAME environment variable |
| 42 | QUERY_STRING='query=namazu' |
| 43 | export QUERY_STRING |
| 44 | SCRIPT_NAME='namazu-l'`perl -e 'print "o" x 2048'`'ng.cgi' |
| 45 | export SCRIPT_NAME |
| 46 | ./namazu.cgi >> $LOG 2>&1 |
| 47 | test $? -ne 0 && exit 1 |
| 48 | |
| 49 | # long HOME environment variable |
| 50 | HOME='/home/l'`perl -e 'print "o" x 2048'`'ong-dir' |
| 51 | export HOME |
| 52 | env NAMAZUNORC='SYSCONFIG' ./namazu.cgi >> $LOG 2>&1 |
| 53 | test $? -ne 0 && exit 1 |
| 54 | |
| 55 | # long LANG environment variable |
| 56 | LANG='ja_JP.eucJP-l'`perl -e 'print "o" x 2048'`'ong' >> $LOG 2>&1 |
| 57 | export LANG >> $LOG 2>&1 |
| 58 | ./namazu.cgi >> $LOG 2>&1 |
| 59 | test $? -ne 0 && exit 1 |
| 60 | |
| 61 | exit 0 |