-
Notifications
You must be signed in to change notification settings - Fork 19
/
configure
executable file
·483 lines (415 loc) · 13 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
#!/bin/sh
# GNU Autotools might not be available on all platforms
# CONVERSELY, sh is available on most platforms (except windows)
# So, just set everything up, and do the magic.
# NOTE: use a configure.bat file for windows.
if [ "$1" = "-h" -o "$1" = "--help" ]; then
echo Options:
echo " --prefix=path prefix path to install sfuzz and its datafiles"
echo " --cross= set the cross-compiler prefix"
echo " --cc= set the name of the compiler"
echo " --cflags= set additional cflags for compilation"
echo " --ldflags= set additional ldflags for compilation"
echo " --enable-snoop turn on snoop compilation"
echo " --enable-plugin-samples compile plugin samples as well"
echo " --disable-plugins compile without plugin support"
echo " --force-symbols compile sfuzz plugins with extra symbols"
echo " --enable-profiling compile sfuzz and plugins with profiling data"
echo " --aux-search-path Auxiliary search path for sfuzz plugins"
echo " --help this message"
exit 0
fi
echo
echo "Starting simple fuzzer auto configuration ..."
WHICH=/usr/bin/which
SED=`$WHICH sed 2> /dev/null`
CAT=`$WHICH cat 2> /dev/null`
UNAME=`$WHICH uname 2> /dev/null`
DIRNAME=`$WHICH dirname 2> /dev/null`
BASENAME=`$WHICH basename 2> /dev/null`
CP=`$WHICH cp 2> /dev/null`
LS=`$WHICH ls 2> /dev/null`
GZIP=`$WHICH gzip 2> /dev/null`
GREP=`$WHICH grep 2> /dev/null`
RM=`$WHICH rm 2> /dev/null`
MKDIR=`$WHICH mkdir 2> /dev/null`
MV=`$WHICH mv 2> /dev/null`
MKTEMP=`$WHICH mktemp 2> /dev/null`
FIND=`$WHICH find 2> /dev/null`
TAR=`$WHICH tar 2> /dev/null`
CUT=`$WHICH cut 2> /dev/null`
XARGS=`$WHICH xargs 2> /dev/null`
MD5SUM=`$WHICH md5sum 2> /dev/null`
GIT=`$WHICH git 2> /dev/null`
if [ -e "$GIT" -a -e ".git/" ]; then
MAINT="$($GIT config user.name) <$($GIT config user.email)>"
else
MAINT="Aaron Conole <[email protected]>"
fi
ARCH=`$UNAME -m`
if [ -e Makefile ]; then
echo "WARNING: You have a previous makefile. I'm moving it to Makefile.old"
echo " If a Makefile.old already exists, it will be overwritten"
$MV -f Makefile Makefile.old
fi
PREFIX=""
SSL_PATH=""
SSL_IPATH=""
CRYPTO_PATH=""
SSL_PLUGIN_SUPPORT=""
CROSS_COMPILE=""
PLUGIN_SUPPORT=""
SNOOP_SUPPORT=""
CC_CHECK=""
LIBDIRS=`$CAT /etc/ld.so.conf 2> /dev/null`
OS_SYSTEM=`$UNAME -s 2> /dev/null`
XCFLAGS="-g -O2 -Wall -Werror -I."
XCFLAGS_EXTRA=""
XLDFLAGS=""
XSHARED_LIBS=""
XSHARED_OPTS=""
XSHARED_INC=""
FORCE_SYMBOLS="N"
PROFILING_DATA="N"
HAS_INSTALL=`$WHICH install 2> /dev/null`
if [ '!' "X" = "X$*" ]; then
while [ $# -gt 0 ];
do
if [ "X" = "X$PREFIX" ]; then
PREFIX_TMP=`echo "$1"|$SED 's/.*--prefix=//'`
if [ "$PREFIX_TMP" != "$1" ]; then
PREFIX=$PREFIX_TMP
fi
fi
if [ "X" = "X$CROSS_COMPILE" ]; then
CROSS_COMPILE_TMP=`echo "$1"|$SED 's/.*--cross=//'`
if [ "$CROSS_COMPILE_TMP" != "$1" ]; then
CROSS_COMPILE=${CROSS_COMPILE_TMP}-
fi
fi
if [ "X" = "X$CC_CHECK" ]; then
CC_CHECK_TMP=`echo "$1"|$SED 's/.*--cc=//'`
if [ "$CC_CHECK_TMP" != "$1" ]; then
CC_CHECK=$CC_CHECK_TMP
fi
fi
if [ "X" = "X$XCFLAGS_EXTRA" ]; then
XCFLAGS_EXTRA_TMP=`echo "$1"|$SED 's/.*--cflags=//'`
if [ "$XCFLAGS_EXTRA_TMP" != "$1" ]; then
XCFLAGS_EXTRA=$XCFLAGS_EXTRA_TMP
fi
fi
if [ "X" = "X$AUX_SEARCH_PATH" ]; then
XAUXSEARCH=`echo "$1"|$SED 's/.*--aux-search-path=//'`
if [ "$XAUXSEARCH" != "$1" ]; then
AUX_SEARCH_PATH="-DAUXSEARCHPATH=\\\":$XAUXSEARCH\\\""
fi
fi
if [ "X" = "X$XLDFLAGS" ]; then
LDFLAGS_EXTRA_TMP=`echo "$1"|$SED 's/.*--ldflags=//'`
if [ "$LDFLAGS_EXTRA_TMP" != "$1" ]; then
XLDFLAGS=$LDFLAGS_EXTRA_TMP
fi
fi
if [ "X" = "X$SSL_PLUGIN_SUPPORT" ]; then
SSL_PLUGIN_SUPPORT_TMP=`echo "$1"|$SED 's/.*--enable-plugin-samples//'`
if [ -z "$SSL_PLUGIN_SUPPORT_TMP" ]; then
SSL_PLUGIN_SUPPORT="enable"
fi
fi
if [ "X" = "X$SNOOP_SUPPORT" ]; then
SNOOP_SUPPORT_TMP=`echo "$1"|$SED 's/.*--enable-snoop//'`
if [ -z "$SNOOP_SUPPORT_TMP" ]; then
SNOOP_SUPPORT="enable"
fi
fi
if [ "X" = "X$PLUGIN_SUPPORT" ]; then
PLUGIN_SUPPORT_TMP=`echo "$1"|$SED 's/.*--disable-plugins//'`
if [ -z $PLUGIN_SUPPORT_TMP ]; then
echo "ahahaha"
PLUGIN_SUPPORT="disable"
SSL_PLUGIN_SUPPORT="disable"
fi
fi
if [ "XN" = "X$FORCE_SYMBOLS" ]; then
FORCE_TMP=`echo "$1"|$SED 's/.*--force-symbols//'`
if [ -z $FORCE_TMP ]; then
FORCE_SYMBOLS="Y"
fi
fi
if [ "XN" = "X$PROFILING_DATA" ]; then
FORCE_TMP=`echo "$1"|$SED 's/.*--enable-profiling//'`
if [ -z $FORCE_TMP ]; then
PROFILING_DATA="Y"
fi
fi
shift
done
fi
if [ "X" = "X$PREFIX" ]; then
PREFIX="/usr/local"
fi
if [ "X" = "X$CC_CHECK" ]; then
CC_CHECK="gcc"
fi
if [ "X" = "X$PLUGIN_SUPPORT" ]; then
PLUGIN_SUPPORT="enable"
fi
CC_LOCATION=`$WHICH ${CROSS_COMPILE}${CC_CHECK} 2> /dev/null`
XCFLAGS="$XCFLAGS -DPREFIX=\\\"$PREFIX\\\" $AUX_SEARCH_PATH"
if [ "X" = "X$HAS_INSTALL" ]; then
HAS_INSTALL="$CP"
HAS_INSTALL_DIR="$MKDIR -p"
else
HAS_INSTALL_DIR="$HAS_INSTALL -d"
fi
if [ "X" = "X$OS_SYSTEM" ]; then
echo "WARN: unable to determine OS type using uname - defaulting to linux"
echo " ... this could be bad. Ensure uname is available."
OS_SYSTEM="Linux"
fi
echo -n "Checking for $CC_CHECK ..."
if [ "X" = "X$CC_LOCATION" ]; then
echo " ... NOT found"
if [ "${CROSS_COMPILE}gcc" != "${CROSS_COMPILE}${CC_CHECK}" ]; then
echo -n "Checking for gcc ..."
CC_LOCATION=`$WHICH ${CROSS_COMPILE}gcc 2> /dev/null`
if [ "X" = "X$CC_LOCATION" ]; then
echo " ... NOT found"
fi
fi
if [ "X" = "X$CC_LOCATION" ]; then
echo -n "Checking for cc ..."
CC_LOCATION=`$WHICH ${CROSS_COMPILE}cc 2> /dev/null`
if [ "X" = "X$CC_LOCATION" ]; then
echo " ... NOT found"
echo " ERROR: No C compiler available. If you think this is in error, manually edit the configure script and set the CC_LOCATION value"
exit 1
fi
fi
fi
echo " ... found"
CC_LOCATION_VAL=`$DIRNAME $CC_LOCATION`
CC_COMPILER_VAL=`$BASENAME $CC_LOCATION`
AR_VAL=`$WHICH ${CROSS_COMPILE}ar`
echo -n "Checking for libssl (openssl/ssl.h) ..."
for i in $LIBDIRS /lib /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu /opt/local/lib \
/*ssl /usr/*ssl /opt/*ssl /usr/local/*ssl /opt/local/*ssl \
/*ssl/lib /usr/*ssl/lib /opt/*ssl/lib /usr/local/*ssl/lib /opt/local/*ssl/lib .
do
if [ "X" = "X$SSL_PATH" ]; then
if [ -f "$i/libssl.so" -o -f "$i/libssl.dylib" ]; then
SSL_PATH="$i"
fi
fi
if [ "X" = "X$SSL_PATH" ]; then
TMP_LIB=`$LS $i/libssl.so* /bin/cygssl*.dll 2> /dev/null | $GREP ssl`
if [ -n "$TMP_LIB" ]; then
SSL_PATH="$i"
fi
fi
if [ "X" = "X$CRYPTO_PATH" ]; then
if [ -f "$i/libcrypto.so" -o -f "$i/libcrypto.dylib" ]; then
CRYPTO_PATH="$i"
fi
fi
if [ "X" = "X$CRYPTO_PATH" ]; then
TMP_LIB=`$LS $i/libcrypto.so* /bin/cygcrypto*.dll 2> /dev/null | $GREP crypto`
if [ -n "$TMP_LIB" ]; then
CRYPTO_PATH="$i"
fi
fi
done
for i in /usr/local/include /*ssl/include /usr/include \
/opt/*ssl/include /usr/*ssl/include /usr/local/*ssl/include .
do
if [ "X" = "X$SSL_IPATH" ]; then
if [ -f "$i/openssl/ssl.h" ]; then
SSL_IPATH="$i"
fi
fi
done
if [ "X" = "X$SSL_PATH" ]; then
SSL_IPATH=""
CRYPTO_PATH=""
fi
if [ "X" = "X$SSL_IPATH" ]; then
SSL_PATH=""
CRYPTO_PATH=""
fi
if [ -n "$SSL_PATH" ]; then
echo " ... found"
fi
if [ "X" = "X$SSL_PATH" ]; then
echo " ... NOT found, support disabled"
echo "*** for the sample ssl plugin get it from http://www.openssl.org ***"
if [ "X" != "X$SSL_PLUGIN_SUPPORT" ]; then
echo "WARN: Disabled ssl plugin building support."
SSL_PLUGIN_SUPPORT="disable"
fi
fi
# to test for features
TESTC=`${MKTEMP} -d /tmp/sfuzz-feattest.XXXXXX`
echo -n "Checking for libdl support ..."
if [ -e "$TESTC" ]; then
$CAT > ${TESTC}/dltest.c <<EOF
#include <stdio.h>
#include <dlfcn.h>
int main()
{
void *foo = dlopen("/var/log/asdf.so", 0);
if( foo )
printf("Found!!\n");
return 0;
}
EOF
${CROSS_COMPILE}${CC_CHECK} -o ${TESTC}/test ${TESTC}/dltest.c -ldl 2>/dev/null >/dev/null
if [ $? -eq 0 ]; then
echo " ... found"
HAVE_LIBDL="YES"
else
HAVE_LIBDL=""
echo " ... NOT found, support disabled"
fi
echo -n "Platform provides memmem ..."
$CAT > ${TESTC}/memmemtest.c <<EOF
#define _GNU_SOURCE 1
#include <string.h>
int main(int argc, char *argv[])
{
if( argc < 1 )
return -1;
void *p = memmem( argv[0], strlen(argv[0]),
"memmem", strlen("memmem") );
if( !p )
return -2;
return 0;
}
EOF
${CROSS_COMPILE}${CC_CHECK} -o ${TESTC}/memmem ${TESTC}/memmemtest.c 2>/dev/null >/dev/null
if [ $? -eq 0 ]; then
echo " ... found"
HAVE_MEMMEM="YES"
else
echo " ... NOT found, using sfuzz's"
HAVE_MEMMEM=""
fi
###
# end feature check
###
${RM} -rf ${TESTC}
else
echo "WARNING: Unable to test for features - assuming the worst"
HAVE_LIBDL=""
HAVE_MEMMEM=""
fi
LIBS=""
#####
# First do generic platform stuff...
#####
if [ "Darwin" = "$OS_SYSTEM" ]; then
XCFLAGS="$XCFLAGS "
SFO_PLATFORM=" sfuzz_oracle_null.o"
SNOOP_SUPPORT="disable"
elif [ "Linux" = "$OS_SYSTEM" ]; then
SFO_PLATFORM=" sfuzz_oracle_ptrace.o"
XCFLAGS="$XCFLAGS -D_GNU_SOURCE"
XSHARED_OPTS="$XSHARED_OPTS"
fi
if [ "X$HAVE_LIBDL" != "X" ]; then
XCFLAGS="$XCFLAGS -fPIC"
XSHARED_LIBS="$XSHARED_LIBS -ldl"
LIBS="$XSHARED_LIBS"
if [ "Darwin" = "$OS_SYSTEM" ]; then
XCFLAGS="$XCFLAGS "
XSHARED_OPTS="$XSHARED_OPTS -dynamiclib -undefined dynamic_lookup -single_module"
elif [ "Linux" = "$OS_SYSTEM" ]; then
XCFLAGS="$XCFLAGS -rdynamic"
XSHARED_OPTS="$XSHARED_OPTS -shared -rdynamic"
fi
if [ "$FORCE_SYMBOLS" = "Y" ]; then
XSHARED_INC=" os-abs.o "
fi
fi
if [ "XY" = "X$PROFILING_DATA" ]; then
XCFLAGS="$XCFLAGS -fprofile-arcs -ftest-coverage"
XLDFLAGS="$XLDFLAGS -fprofile-arcs -ftest-coverage"
fi
if [ "X${HAVE_MEMMEM}" != "X" ]; then
XCFLAGS="$XCFLAGS -DHAVE_MEMMEM=1 "
fi
if [ $PLUGIN_SUPPORT = "disable" ]; then
XCFLAGS_EXTRA="-DNOPLUGIN"
fi
SFUZZ_VERSION=`$GREP define\ VERSION version.h | $CUT -d" " -f3 | $SED 's/"//g'`
echo "Done configuring ... writing Makefile"
$CAT > Makefile <<__MAKEFILE_EOF__
# This file was automatically built by the simple fuzzer configuration process
# Manual edits will not be saved if you run configure again
# you have been warned.
### Variables for building
MKTEMP=$MKTEMP
CCPATH=$CC_LOCATION_VAL
CC=$CC_COMPILER_VAL
AR=$AR_VAL
FIND=$FIND
GZIP=$GZIP
TAR=$TAR
MAINT=$MAINT
ARCH=$ARCH
XARGS=$XARGS
VERSION=$SFUZZ_VERSION
MD5SUM=$MD5SUM
INSTALL=$HAS_INSTALL
INSTALL_DIR=$HAS_INSTALL_DIR
CFLAGS=$XCFLAGS $XCFLAGS_EXTRA
LDFLAGS=$XLDFLAGS
TARGET_PLAT=$OS_SYSTEM
CP=$CP
SED=$SED
CAT=$CAT
UNAME=$UNAME
DIRNAME=$DIRNAME
BASENAME=$BASENAME
LS=$LS
GREP=$GREP
PREFIX=$PREFIX
RM=$RM
MKDIR=$MKDIR
SHARED_INC=$XSHARED_INC
SHARED_OPTS=$XSHARED_OPTS
SF_OBJS=file-utils.o sfuzz.o os-abs.o sfo_interface.o
SNOOP_OBJS=snoop.o os-abs.o
SFO_OBJS=sfuzz_oracle.o $SFO_PLATFORM
PLUGIN_EXAMPLE_OBJS=sfuzz-plugin-example.o sfuzz-plugin-ssl-transport.o sfuzz-server-plugin.o
LIBS=$LIBS
BIN_DIR=$PREFIX/bin/
SHARE_DIR=$PREFIX/share/
MAN_DIR=$PREFIX/share/man/man1/
SFUZZ_SAMPLE=sfuzz-sample/
__MAKEFILE_EOF__
# now to determine targets (ie: sfuzz is obvious, but snoop and plugins are
# also required
PROGS="sfuzz sfo sfuzz.1.gz sfo.1.gz"
if [ $PLUGIN_SUPPORT = "enable" ]; then
PROGS="$PROGS sfuzz-plugin-example.so sfuzz-server-plugin.so "
if [ "$SSL_PLUGIN_SUPPORT" = "enable" ]; then
PROGS="$PROGS sfuzz-plugin-ssl-transport.so"
fi
fi
if [ "$SNOOP_SUPPORT" = "enable" ]; then
PROGS="$PROGS snoop"
fi
$CAT >> Makefile <<__MAKEFILE_EOF__
PROGS=$PROGS
all: $PROGS
@echo Finished building.
__MAKEFILE_EOF__
$CAT ./Makefile.in >> Makefile
echo "Writing spec file"
SFUZZ_MAINVERSION=`echo $SFUZZ_VERSION | $SED -e 's/"//g' | $SED -re 's/^([0-9]+)\.([0-9]+)\.[0-9]+$/\1.\2/g'`
SFUZZ_RELEASE=`echo $SFUZZ_VERSION | $CUT -d"." -f3`
echo "Wrote $SFUZZ_MAINVERSION : $SFUZZ_RELEASE"
$SED -e "s@VERSION@$SFUZZ_MAINVERSION\.$SFUZZ_RELEASE@g" < ./simple-fuzzer.spec.in | $SED -e "s@MAINVER@$SFUZZ_MAINVERSION@g" | $SED -e "s@RELEASE@$SFUZZ_RELEASE@g" > ./simple-fuzzer.spec
echo "Finished. Now run 'make'"
exit 0