1#!/bin/bash 2 3# A little script to run tshark on capture file[s] (potentially ones that 4# failed fuzz testing). Useful because it sets up ulimits and other environment 5# variables for you to ensure things like misused ephemeral memory are caught. 6# (I'm writing this after having my machine hang up for like 15 minutes because 7# I wasn't paying attention while tshark was running on a fuzzed capture and 8# it used all my RAM + swap--which was pretty painful.) 9# 10# Copyright 2012 Jeff Morriss <jeff.morriss.ws [AT] gmail.com> 11# 12# Wireshark - Network traffic analyzer 13# By Gerald Combs <gerald@wireshark.org> 14# Copyright 1998 Gerald Combs 15# 16# SPDX-License-Identifier: GPL-2.0-or-later 17 18TEST_TYPE="manual" 19# shellcheck source=tools/test-common.sh 20. "$( dirname "$0" )"/test-common.sh || exit 1 21 22# Run under AddressSanitizer ? 23ASAN=$CONFIGURED_WITH_ASAN 24 25while getopts "ab:" OPTCHAR ; do 26 case $OPTCHAR in 27 a) ASAN=1 ;; 28 b) WIRESHARK_BIN_DIR=$OPTARG ;; 29 *) printf "Unknown option: %s\\n" "$OPTARG" 30 esac 31done 32shift $(( OPTIND - 1 )) 33 34if [ $# -lt 1 ] 35then 36 printf "Usage: %s [-b bin_dir] /path/to/file[s].pcap\\n" "$( basename "$0" )" 37 exit 1 38fi 39 40ws_bind_exec_paths 41ws_check_exec "$TSHARK" 42 43# Set some limits to the child processes, e.g. stop it if it's running 44# longer than MAX_CPU_TIME seconds. (ulimit is not supported well on 45# cygwin - it shows some warnings - and the features we use may not all 46# be supported on some UN*X platforms.) 47ulimit -S -t $MAX_CPU_TIME 48 49# Allow core files to be generated 50ulimit -c unlimited 51 52# Don't enable ulimit -v when using ASAN. See 53# https://github.com/google/sanitizers/wiki/AddressSanitizer#ulimit--v 54if [ $ASAN -eq 0 ]; then 55 ulimit -S -v $MAX_VMEM 56fi 57 58for file in "$@" 59do 60 echo "Testing file $file..." 61 echo -n " - with tree... " 62 if $TSHARK -nVxr "$file" > /dev/null 63 then 64 echo "OK" 65 echo -n " - without tree... " 66 if "$WIRESHARK_BIN_DIR/tshark" -nr "$file" > /dev/null 67 then 68 echo "OK" 69 echo -n " - without tree but with a read filter... " 70 if "$WIRESHARK_BIN_DIR/tshark" -Yframe -nr "$file" > /dev/null 71 then 72 echo "OK" 73 else 74 echo "Failed" 75 exit 1 76 fi 77 else 78 echo "Failed" 79 exit 1 80 fi 81 else 82 echo "Failed" 83 exit 1 84 fi 85done 86