3 # Copyright 2013 Gerald Combs <gerald@wireshark.org>
7 # Wireshark - Network traffic analyzer
8 # By Gerald Combs <gerald@wireshark.org>
9 # Copyright 1998 Gerald Combs
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 # Common variables and functions for fuzz and randpkt tests.
27 # This needs to point to a 'date' that supports %s.
28 if [ -z "$TEST_TYPE" ] ; then
29 echo "TEST_TYPE must be defined by the sourcing script."
34 BASE_NAME
=$TEST_TYPE-`$DATE +%Y-%m-%d`-$$
36 # Directory containing binaries. Default current directory.
39 # Temporary file directory and names.
40 # (had problems with this on cygwin, tried TMP_DIR=./ which worked)
42 if [ "$OSTYPE" == "cygwin" ] ; then
43 TMP_DIR
=`cygpath --windows "$TMP_DIR"`
45 TMP_FILE
=$BASE_NAME.pcap
46 ERR_FILE
=$BASE_NAME.err
48 # Loop this many times (< 1 loops forever)
51 # These may be set to your liking
52 # Stop the child process if it's running longer than x seconds
54 # Stop the child process if it's using more than y * 1024 bytes
56 # Stop the child process if its stack is larger than than z * 1024 bytes
63 # Insert z times an error into the capture file (0.02 seems to be a good value to find errors)
66 # Tweak the following to your liking. Editcap must support "-E".
67 TSHARK
="$BIN_DIR/tshark"
68 EDITCAP
="$BIN_DIR/editcap"
69 CAPINFOS
="$BIN_DIR/capinfos"
70 RANDPKT
="$BIN_DIR/randpkt"
72 if [ "$BIN_DIR" = "." ]; then
73 export WIRESHARK_RUN_FROM_BUILD_DIRECTORY
=1
76 ##############################################################################
77 ### Set up environment variables for fuzz testing ###
78 ##############################################################################
79 # Initialize (ep_ and se_) allocated memory to 0xBADDCAFE and freed memory
81 export WIRESHARK_DEBUG_SCRUB_MEMORY
=
82 # Use canaries in se_ allocations (off by default due to the memory usage)
83 export WIRESHARK_DEBUG_SE_USE_CANARY
=
84 # Verify that ep_ and se_ allocated memory is not passed to certain routines
85 # which need the memory to be persistent.
86 export WIRESHARK_EP_VERIFY_POINTERS
=
87 export WIRESHARK_SE_VERIFY_POINTERS
=
88 # Use the Wmem strict allocator which does canaries and scrubbing etc.
89 export WIRESHARK_DEBUG_WMEM_OVERRIDE
=strict
90 # Abort if a dissector adds too many items to the tree
91 export WIRESHARK_ABORT_ON_TOO_MANY_ITEMS
=
93 # Turn on GLib memory debugging (since 2.13)
94 export G_SLICE
=debug-blocks
95 # Cause glibc (Linux) to abort() if some memory errors are found
96 export MALLOC_CHECK_
=3
97 # Cause FreeBSD (and other BSDs) to abort() on allocator warnings and
98 # initialize allocated memory (to 0xa5) and freed memory (to 0x5a). see:
99 # http://www.freebsd.org/cgi/man.cgi?query=malloc&apropos=0&sektion=0&manpath=FreeBSD+8.2-RELEASE&format=html
100 export MALLOC_OPTIONS
=AJ
102 # MacOS options; see http://developer.apple.com/library/mac/releasenotes/DeveloperTools/RN-MallocOptions/_index.html
103 # Initialize allocated memory to 0xAA and freed memory to 0x55
104 export MallocPreScribble
=1
105 export MallocScribble
=1
106 # Add guard pages before and after large allocations
107 export MallocGuardEdges
=1
108 # Call abort() if heap corruption is detected. Heap is checked every 1000
109 # allocations (may need to be tuned!)
110 export MallocCheckHeapStart
=1000
111 export MallocCheckHeapEach
=1000
112 export MallocCheckHeapAbort
=1
113 # Call abort() if an illegal free() call is made
114 export MallocBadFreeAbort
=1
116 # Create an error report
117 function exit_error
() {
119 echo -e "Processing failed. Capture info follows:\n"
120 echo " Input file: $CF"
121 echo " Output file: $TMP_DIR/$TMP_FILE"
124 # Fill in build information
125 echo -e "Input file: $CF\n" > $TMP_DIR/${ERR_FILE}.header
126 echo -e "Build host information:" >> $TMP_DIR/${ERR_FILE}.header
127 uname
-a >> $TMP_DIR/${ERR_FILE}.header
128 lsb_release
-a >> $TMP_DIR/${ERR_FILE}.header
2> /dev
/null
130 if [ -n "$BUILDBOT_BUILDERNAME" ] ; then
131 echo -e "\nBuildbot information:" >> $TMP_DIR/${ERR_FILE}.header
132 env |
grep "^BUILDBOT_" >> $TMP_DIR/${ERR_FILE}.header
135 echo -e "\nReturn value: " $RETVAL >> $TMP_DIR/${ERR_FILE}.header
136 echo -e "\nDissector bug: " $DISSECTOR_BUG >> $TMP_DIR/${ERR_FILE}.header
137 echo -e "\nValgrind error count: " $VG_ERR_CNT >> $TMP_DIR/${ERR_FILE}.header
139 echo -e "\n" >> $TMP_DIR/${ERR_FILE}.header
141 if [ -d .svn
] ; then
142 echo -e "\nSubversion revision" >> $TMP_DIR/${ERR_FILE}.header
143 svn log
-l 1 >> $TMP_DIR/${ERR_FILE}.header
144 elif [ -d .git
] ; then
145 echo -e "\nGit commit" >> $TMP_DIR/${ERR_FILE}.header
146 git log
-1 >> $TMP_DIR/${ERR_FILE}.header
149 echo -e "\n" >> $TMP_DIR/${ERR_FILE}.header
151 # Trim the stderr output if needed
152 ERR_SIZE
=$
(du
-sk $TMP_DIR/$ERR_FILE |
awk '{ print $1 }')
153 if [ $ERR_SIZE -ge 5000 ] ; then
154 mv $TMP_DIR/$ERR_FILE $TMP_DIR/${ERR_FILE}.full
155 head -n 2000 $TMP_DIR/${ERR_FILE}.full
> $TMP_DIR/$ERR_FILE
156 echo -e "\n\n[ Output removed ]\n\n" >> $TMP_DIR/$ERR_FILE
157 tail -n 2000 $TMP_DIR/${ERR_FILE}.full
>> $TMP_DIR/$ERR_FILE
158 rm -f $TMP_DIR/${ERR_FILE}.full
161 cat $TMP_DIR/${ERR_FILE} >> $TMP_DIR/${ERR_FILE}.header
162 mv $TMP_DIR/${ERR_FILE}.header
$TMP_DIR/${ERR_FILE}
164 echo -e "stderr follows:\n"
165 cat $TMP_DIR/$ERR_FILE