diff --git a/tools/fuzz-test.sh b/tools/fuzz-test.sh index 217670558c..b390c60bd8 100755 --- a/tools/fuzz-test.sh +++ b/tools/fuzz-test.sh @@ -37,6 +37,9 @@ TWO_PASS= # Specific config profile ? CONFIG_PROFILE= +# Run under valgrind ? +VALGRIND=0 + # These may be set to your liking # Stop the child process if it's running longer than x seconds MAX_CPU_TIME=900 @@ -60,14 +63,15 @@ ERR_PROB=0.02 # To do: add options for file names and limits -while getopts ":b:d:e:C:Pp:" OPTCHAR ; do +while getopts ":2b:d:e:gC:p:" OPTCHAR ; do case $OPTCHAR in + 2) TWO_PASS="-2 " ;; b) BIN_DIR=$OPTARG ;; C) CONFIG_PROFILE="-C $OPTARG " ;; d) TMP_DIR=$OPTARG ;; e) ERR_PROB=$OPTARG ;; + g) VALGRIND=1 ;; p) MAX_PASSES=$OPTARG ;; - P) TWO_PASS="-P " ;; esac done shift $(($OPTIND - 1)) @@ -88,12 +92,20 @@ ulimit -c unlimited ### usually you won't have to change anything below this line ### -# TShark arguments (you won't have to change these) -# n Disable network object name resolution -# V Print a view of the details of the packet rather than a one-line summary of the packet -# x Cause TShark to print a hex and ASCII dump of the packet data after printing the summary or details -# r Read packet data from the following infile -TSHARK_ARGS="${CONFIG_PROFILE}${TWO_PASS}-nVxr" +if [ $VALGRIND -eq 1 ]; then + RUNNER="$BIN_DIR/tools/valgrind-wireshark.sh" + RUNNER_ARGS="${CONFIG_PROFILE}${TWO_PASS}" +else + # Not using valgrind, use regular tshark. + # TShark arguments (you won't have to change these) + # n Disable network object name resolution + # V Print a view of the details of the packet rather than a one-line summary of the packet + # x Cause TShark to print a hex and ASCII dump of the packet data after printing the summary or details + # r Read packet data from the following infile + RUNNER="$TSHARK" + RUNNER_ARGS="${CONFIG_PROFILE}${TWO_PASS}-nVxr" +fi + NOTFOUND=0 for i in "$TSHARK" "$EDITCAP" "$CAPINFOS" "$DATE" "$TMP_DIR" ; do @@ -136,7 +148,7 @@ HOWMANY="forever" if [ $MAX_PASSES -gt 0 ]; then HOWMANY="$MAX_PASSES passes" fi -echo "Running $TSHARK with args: $TSHARK_ARGS ($HOWMANY)" +echo "Running $RUNNER with args: $RUNNER_ARGS ($HOWMANY)" echo "" # Clean up on C, etc @@ -218,6 +230,7 @@ while [ \( $PASS -lt $MAX_PASSES -o $MAX_PASSES -lt 1 \) -a $DONE -ne 1 ] ; do fi DISSECTOR_BUG=0 + VG_ERR_CNT=0 "$EDITCAP" -E $ERR_PROB "$CF" $TMP_DIR/$TMP_FILE > /dev/null 2>&1 if [ $? -ne 0 ] ; then @@ -229,14 +242,22 @@ while [ \( $PASS -lt $MAX_PASSES -o $MAX_PASSES -lt 1 \) -a $DONE -ne 1 ] ; do fi fi - "$TSHARK" $TSHARK_ARGS $TMP_DIR/$TMP_FILE \ + "$RUNNER" $RUNNER_ARGS $TMP_DIR/$TMP_FILE \ > /dev/null 2>> $TMP_DIR/$ERR_FILE RETVAL=$? + # Uncomment the next two lines to enable dissector bug # checking. #grep -i "dissector bug" $TMP_DIR/$ERR_FILE \ # > /dev/null 2>&1 && DISSECTOR_BUG=1 - if [ \( $RETVAL -ne 0 -o $DISSECTOR_BUG -ne 0 \) -a $DONE -ne 1 ] ; then + + if [ $VALGRIND -eq 1 ]; then + VG_ERR_CNT="`grep "ERROR SUMMARY:" $TMP_DIR/$ERR_FILE | cut -f4 -d' '`" + fi + + if [ \( $RETVAL -ne 0 -o $DISSECTOR_BUG -ne 0 -o $VG_ERR_CNT -ne 0 \) \ + -a $DONE -ne 1 ] ; then + echo "" echo " ERROR" echo -e "Processing failed. Capture info follows:\n" diff --git a/tools/valgrind-wireshark.sh b/tools/valgrind-wireshark.sh index 63fa8e210d..512f000018 100755 --- a/tools/valgrind-wireshark.sh +++ b/tools/valgrind-wireshark.sh @@ -33,27 +33,29 @@ COMMAND=tshark COMMAND_ARGS="-nVxr" COMMAND_ARGS2= -while getopts ":b:ltwce" OPTCHAR ; do +while getopts ":2b:C:ltwce" OPTCHAR ; do case $OPTCHAR in + 2) COMMAND_ARGS="-2 $COMMAND_ARGS" ;; b) BIN_DIR=$OPTARG ;; + C) COMMAND_ARGS="-C $OPTARG $COMMAND_ARGS" ;; l) LEAK_CHECK="--leak-check=full" ;; t) TRACK_ORIGINS="--track-origins=yes" ;; - w) COMMAND=wireshark - COMMAND_ARGS="-nr" ;; - c) COMMAND=capinfos - COMMAND_ARGS="" ;; - e) COMMAND=editcap - COMMAND_ARGS="-E 0.02" - # We don't care about the output of editcap - COMMAND_ARGS2="/dev/null" ;; + w) COMMAND=wireshark + COMMAND_ARGS="-nr" ;; + c) COMMAND=capinfos + COMMAND_ARGS="" ;; + e) COMMAND=editcap + COMMAND_ARGS="-E 0.02" + # We don't care about the output of editcap + COMMAND_ARGS2="/dev/null" ;; esac done shift $(($OPTIND - 1)) if [ $# -ne 1 ] then - printf "Usage: $0 [-b bin_dir] [-l] [-t] [-w] /path/to/file.pcap\n" - exit 1 + printf "Usage: $0 [-2] [-b bin_dir] [-C config_profile] [-l] [-t] [-w] /path/to/file.pcap\n" + exit 1 fi if [ "$BIN_DIR" = "." ]; then