avoid calling awk for 'which' replacement, use POSIX 'command -v' instead
MODIFY
afl-cmin
afl-cmin
@@ -264,7 +264,7 @@ BEGIN {
if (target_bin && !exists_and_is_executable(target_bin)) {
- "type "target_bin" | awk '{print $NF}' 2>/dev/null" | getline tnew
+ "command -v "target_bin" 2>/dev/null" | getline tnew
if (!tnew || !exists_and_is_executable(tnew)) {
print "[-] Error: binary '"target_bin"' not found or not executable." > "/dev/stderr"
exit 1
@@ -313,7 +313,7 @@ BEGIN {
if (0 == system("test -f afl-cmin")) {
showmap = "./afl-showmap"
} else {
- "type afl-showmap | awk '{print $NF}' 2>/dev/null" | getline showmap
+ "command -v afl-showmap 2>/dev/null" | getline showmap
}
} else {
showmap = ENVIRON["AFL_PATH"] "/afl-showmap"

MODIFY
afl-plot
afl-plot
@@ -68,7 +68,7 @@ BANNER="`cat "$1/fuzzer_stats" | grep '^afl_banner ' | cut -d: -f2- | cut -b2-`"
test "$BANNER" = "" && BANNER="(none)"
-GNUPLOT=`type gnuplot | awk '{print $NF}' 2>/dev/null`
+GNUPLOT=`command -v gnuplot 2>/dev/null`
if [ "$GNUPLOT" = "" ]; then

MODIFY
gcc_plugin/Makefile
gcc_plugin/Makefile
@@ -44,7 +44,7 @@ PLUGIN_FLAGS = -fPIC -fno-rtti -I"$(shell $(CC) -print-file-name=plugin)/include
HASH=\#
GCCVER = $(shell $(CC) --version 2>/dev/null | awk 'NR == 1 {print $$NF}')
-GCCBINDIR = $(shell dirname `type $(CC) | awk '{print $$NF}'` 2>/dev/null )
+GCCBINDIR = $(shell dirname `command -v $(CC)` 2>/dev/null )
ifeq "$(shell echo '$(HASH)include <sys/ipc.h>@$(HASH)include <sys/shm.h>@int main() { int _id = shmget(IPC_PRIVATE, 65536, IPC_CREAT | IPC_EXCL | 0600); shmctl(_id, IPC_RMID, 0); return 0;}' | tr @ '\n' | $(CC) -x c - -o .test2 2>/dev/null && echo 1 || echo 0 ; rm -f .test2 )" "1"
SHMAT_OK=1

MODIFY
llvm_mode/Makefile
llvm_mode/Makefile
@@ -162,7 +162,7 @@ ifeq "$(shell uname)" "OpenBSD"
CLANG_LFL += `$(LLVM_CONFIG) --libdir`/libLLVM.so
endif
-ifeq "$(shell echo 'int main() {return 0; }' | $(CC) -x c - -fuse-ld=`type ld | awk '{print $$NF}'` -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
+ifeq "$(shell echo 'int main() {return 0; }' | $(CC) -x c - -fuse-ld=`command -v ld` -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
CFLAGS += -DAFL_CLANG_FUSELD=1
endif

MODIFY
qemu_mode/build_qemu_support.sh
qemu_mode/build_qemu_support.sh
@@ -86,7 +86,7 @@ fi
if echo "$CC" | grep -qF /afl-; then
echo "[-] Error: do not use afl-gcc or afl-clang to compile this tool."
- exit 1
+ PREREQ_NOTFOUND=1
fi

MODIFY
test/test.sh
test/test.sh
@@ -223,7 +223,7 @@ test -e ../afl-clang-fast -a -e ../split-switches-pass.so && {
# on FreeBSD need to set AFL_CC
test `uname -s` = 'FreeBSD' && {
if type clang >/dev/null; then
- export AFL_CC=`type clang | awk '{print $NF}'`
+ export AFL_CC=`command -v clang`
else
export AFL_CC=`$LLVM_CONFIG --bindir`/clang
fi
@@ -401,7 +401,7 @@ test -e ../afl-clang-lto -a -e ../afl-llvm-lto-instrumentation.so && {
# on FreeBSD need to set AFL_CC
test `uname -s` = 'FreeBSD' && {
if type clang >/dev/null; then
- export AFL_CC=`type clang | awk '{print $NF}'`
+ export AFL_CC=`command -v clang`
else
export AFL_CC=`$LLVM_CONFIG --bindir`/clang
fi
@@ -471,7 +471,7 @@ test -e ../afl-clang-lto -a -e ../afl-llvm-lto-instrumentation.so && {
}
$ECHO "$BLUE[*] Testing: gcc_plugin"
-export AFL_CC=`type gcc | awk '{print $NF}'`
+export AFL_CC=`command -v gcc`
test -e ../afl-gcc-fast -a -e ../afl-gcc-rt.o && {
../afl-gcc-fast -o test-instr.plain.gccpi ../test-instr.c > /dev/null 2>&1
AFL_HARDEN=1 ../afl-gcc-fast -o test-compcov.harden.gccpi test-compcov.c > /dev/null 2>&1
@@ -617,7 +617,7 @@ test -e ../libradamsa.so && {
test `uname -s` = 'FreeBSD' && {
if type clang >/dev/null; then
- export AFL_CC=`type clang | awk '{print $NF}'`
+ export AFL_CC=`command -v clang`
else
export AFL_CC=`$LLVM_CONFIG --bindir`/clang
fi
@@ -835,7 +835,7 @@ test -d ../unicorn_mode/unicornafl && {
test -e ../unicorn_mode/samples/simple/simple_target.bin -a -e ../unicorn_mode/samples/compcov_x64/compcov_target.bin && {
{
# travis workaround
- PY=`type python | awk '{print $NF}'`
+ PY=`command -v python`
test "$PY" = "/opt/pyenv/shims/python" -a -x /usr/bin/python && PY=/usr/bin/python
mkdir -p in
echo 0 > in/in

avoid calling awk for 'which' replacement, use POSIX 'command -v' instead