3 # Copyright 2013 Gerald Combs <gerald@wireshark.org>
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 1998 Gerald Combs
9 # SPDX-License-Identifier: GPL-2.0-or-later
11 # Common variables and functions for fuzz and randpkt tests.
13 # This needs to point to a 'date' that supports %s.
14 if [ -z "$TEST_TYPE" ] ; then
15 echo "TEST_TYPE must be defined by the sourcing script."
20 BASE_NAME
=$TEST_TYPE-$
($DATE +%Y-
%m-
%d
)-$$
22 # Directory containing binaries. Default: cmake run directory.
23 if [ -z "$WIRESHARK_BIN_DIR" ]; then
27 # Temporary file directory and names.
28 # (had problems with this on cygwin, tried TMP_DIR=./ which worked)
30 if [ "$OSTYPE" == "cygwin" ] ; then
31 TMP_DIR
=$
(cygpath
--windows "$TMP_DIR")
33 TMP_FILE
=$BASE_NAME.pcap
34 ERR_FILE
=$BASE_NAME.err
36 # Loop this many times (< 1 loops forever)
39 # These may be set to your liking
40 # Stop the child process if it's running longer than x seconds
42 # Stop the child process if it's using more than y * 1024 bytes
44 # Stop the child process if its stack is larger than z * 1024 bytes
51 # Insert z times an error into the capture file (0.02 seems to be a good value to find errors)
53 # Maximum number of packets to fuzz
54 MAX_FUZZ_PACKETS
=50000
56 # Call *after* any changes to WIRESHARK_BIN_DIR (e.g., via command-line options)
57 function ws_bind_exec_paths
() {
58 # Tweak the following to your liking. Editcap must support "-E".
59 TSHARK
="$WIRESHARK_BIN_DIR/tshark"
60 EDITCAP
="$WIRESHARK_BIN_DIR/editcap"
61 CAPINFOS
="$WIRESHARK_BIN_DIR/capinfos"
62 RANDPKT
="$WIRESHARK_BIN_DIR/randpkt"
64 if [ "$WIRESHARK_BIN_DIR" = "." ]; then
65 export WIRESHARK_RUN_FROM_BUILD_DIRECTORY
=1
69 function ws_check_exec
() {
72 if [ ! -x "$i" ]; then
73 echo "Couldn't find \"$i\""
77 if [ $NOTFOUND -eq 1 ]; then
82 source "$(dirname "$0")"/debug-alloc.env
84 # Address Sanitizer options
85 export ASAN_OPTIONS
=detect_leaks
=0
87 # See if we were configured with gcc or clang's AddressSanitizer.
88 CONFIGURED_WITH_ASAN
=0
89 # If tshark is built with ASAN this will generate an error. We could
90 # also pass help=1 and look for help text.
91 ASAN_OPTIONS
=Invalid_Option_Flag
$TSHARK -h > /dev
/null
2>&1
92 if [ $?
-ne 0 ] ; then
93 CONFIGURED_WITH_ASAN
=1
95 export CONFIGURED_WITH_ASAN
97 # Create an error report
98 function ws_exit_error
() {
100 echo -e "Processing failed. Capture info follows:\n"
101 echo " Input file: $CF"
102 echo " Output file: $TMP_DIR/$TMP_FILE"
106 # Fill in build information
108 if [ -n "$CI_COMMIT_BRANCH" ] ; then
109 printf "Branch: %s\\n" "$CI_COMMIT_BRANCH"
111 printf "Branch: %s\\n" "$(git rev-parse --abbrev-ref HEAD)"
114 printf "Input file: %s\\n" "$CF"
116 if [ -n "$CI_JOB_NAME" ] ; then
117 printf "CI job name: %s, ID: %s\\n" "$CI_JOB_NAME" "$CI_JOB_ID"
118 printf "CI job URL: %s\\n" "$CI_JOB_URL"
121 printf "Return value: %s\\n" "$RETVAL"
122 printf "Dissector bug: %s\\n" "$DISSECTOR_BUG"
123 if [ "$VALGRIND" -eq 1 ] ; then
124 printf "Valgrind error count: %s\\n" "$VG_ERR_CNT"
127 printf "Date and time: %s\\n" "$( date --utc )"
130 if [ -d "${GIT_DIR:-.git}" ] ; then
131 printf "\\nCommits in the last %s hours:\\n" $SINCE_HOURS
132 git
--no-pager log
--oneline --no-decorate --since=${SINCE_HOURS}hours
136 printf "Build host information:\\n"
138 lsb_release
-a 2> /dev
/null
141 } > "$TMP_DIR/${ERR_FILE}.header"
143 # Trim the stderr output if needed
144 ERR_SIZE
=$
(du
-sk $TMP_DIR/$ERR_FILE |
awk '{ print $1 }')
145 if [ $ERR_SIZE -ge 5000 ] ; then
146 mv $TMP_DIR/$ERR_FILE $TMP_DIR/${ERR_FILE}.full
147 head -n 2000 $TMP_DIR/${ERR_FILE}.full
> $TMP_DIR/$ERR_FILE
148 echo -e "\n\n[ Output removed ]\n\n" >> $TMP_DIR/$ERR_FILE
149 tail -n 2000 $TMP_DIR/${ERR_FILE}.full
>> $TMP_DIR/$ERR_FILE
150 rm -f $TMP_DIR/${ERR_FILE}.full
153 cat $TMP_DIR/${ERR_FILE} >> $TMP_DIR/${ERR_FILE}.header
154 mv $TMP_DIR/${ERR_FILE}.header
$TMP_DIR/${ERR_FILE}
156 echo -e "stderr follows:\n"
157 cat $TMP_DIR/$ERR_FILE