Skip to content

Commit 81ad0d2

Browse files
authored
fix: Quote paths to prevent globbing and word splitting (masonr#82)
1 parent c2ccbc2 commit 81ad0d2

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

bin/compile.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ make
4444
# verify no external shared library links
4545
libcheck fio
4646
# copy fio binary to mounted dir
47-
cp fio /io/fio_$ARCH
47+
cp fio "/io/fio_$ARCH"
4848

4949
# download and compile iperf
5050
cd ~
@@ -57,4 +57,4 @@ make
5757
# verify no external shared library links
5858
libcheck src/iperf3
5959
# copy iperf binary to mounted dir
60-
cp src/iperf3 /io/iperf3_$ARCH
60+
cp src/iperf3 "/io/iperf3_$ARCH"

bin/cross-compile.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ yum install -y xz
1212
# download musl cross compilation toolchain
1313
cd ~
1414
curl -L "https://musl.cc/${CROSS}-cross.tgz" -o "${CROSS}-cross.tgz"
15-
tar xf ${CROSS}-cross.tgz
15+
tar xf "${CROSS}-cross.tgz"
1616

1717
# download, compile, and install libaio as static library
1818
cd ~
@@ -35,17 +35,17 @@ make
3535
# verify no external shared library links
3636
libcheck fio
3737
# copy fio binary to mounted dir
38-
cp fio /io/fio_$ARCH
38+
cp fio "/io/fio_$ARCH"
3939

4040
# download and compile iperf
4141
cd ~
4242
curl -L https://github.com/esnet/iperf/archive/3.15.tar.gz -o "iperf.tar.gz"
4343
tar xf iperf.tar.gz
4444
cd iperf*
45-
CC=/root/${CROSS}-cross/bin/${CROSS}-gcc ./configure --disable-shared --disable-profiling --build x86_64-pc-linux-gnu --host ${HOST} --with-openssl=no --enable-static-bin
45+
CC=/root/${CROSS}-cross/bin/${CROSS}-gcc ./configure --disable-shared --disable-profiling --build x86_64-pc-linux-gnu --host "${HOST}" --with-openssl=no --enable-static-bin
4646
make
4747

4848
# verify no external shared library links
4949
libcheck src/iperf3
5050
# copy iperf binary to mounted dir
51-
cp src/iperf3 /io/iperf3_$ARCH
51+
cp src/iperf3 "/io/iperf3_$ARCH"

yabs.sh

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,15 @@ fi
326326
# create a directory in the same location that the script is being run to temporarily store YABS-related files
327327
DATE=$(date -Iseconds | sed -e "s/:/_/g")
328328
YABS_PATH=./$DATE
329-
touch $DATE.test 2> /dev/null
329+
touch "$DATE.test" 2> /dev/null
330330
# test if the user has write permissions in the current directory and exit if not
331331
if [ ! -f "$DATE.test" ]; then
332332
echo -e
333333
echo -e "You do not have write permission in this directory. Switch to an owned directory and re-run the script.\nExiting..."
334334
exit 1
335335
fi
336-
rm $DATE.test
337-
mkdir -p $YABS_PATH
336+
rm "$DATE.test"
337+
mkdir -p "$YABS_PATH"
338338

339339
# trap CTRL+C signals to exit script cleanly
340340
trap catch_abort INT
@@ -344,7 +344,7 @@ trap catch_abort INT
344344
# yabs-related files.
345345
function catch_abort() {
346346
echo -e "\n** Aborting YABS. Cleaning up files...\n"
347-
rm -rf $YABS_PATH
347+
rm -rf "$YABS_PATH"
348348
unset LC_ALL
349349
exit 0
350350
}
@@ -430,7 +430,7 @@ function disk_test {
430430

431431
# run a quick test to generate the fio test file to be used by the actual tests
432432
echo -en "Generating fio test file..."
433-
$FIO_CMD --name=setup --ioengine=libaio --rw=read --bs=64k --iodepth=64 --numjobs=2 --size=$FIO_SIZE --runtime=1 --gtod_reduce=1 --filename=$DISK_PATH/test.fio --direct=1 --minimal &> /dev/null
433+
$FIO_CMD --name=setup --ioengine=libaio --rw=read --bs=64k --iodepth=64 --numjobs=2 --size=$FIO_SIZE --runtime=1 --gtod_reduce=1 --filename="$DISK_PATH/test.fio" --direct=1 --minimal &> /dev/null
434434
echo -en "\r\033[0K"
435435

436436
# get array of block sizes to evaluate
@@ -439,7 +439,7 @@ function disk_test {
439439
for BS in "${BLOCK_SIZES[@]}"; do
440440
# run rand read/write mixed fio test with block size = $BS
441441
echo -en "Running fio random mixed R+W disk test with $BS block size..."
442-
DISK_TEST=$(timeout 35 $FIO_CMD --name=rand_rw_$BS --ioengine=libaio --rw=randrw --rwmixread=50 --bs=$BS --iodepth=64 --numjobs=2 --size=$FIO_SIZE --runtime=30 --gtod_reduce=1 --direct=1 --filename=$DISK_PATH/test.fio --group_reporting --minimal 2> /dev/null | grep rand_rw_$BS)
442+
DISK_TEST=$(timeout 35 $FIO_CMD --name=rand_rw_$BS --ioengine=libaio --rw=randrw --rwmixread=50 --bs=$BS --iodepth=64 --numjobs=2 --size=$FIO_SIZE --runtime=30 --gtod_reduce=1 --direct=1 --filename="$DISK_PATH/test.fio" --group_reporting --minimal 2> /dev/null | grep rand_rw_$BS)
443443
DISK_IOPS_R=$(echo $DISK_TEST | awk -F';' '{print $8}')
444444
DISK_IOPS_W=$(echo $DISK_TEST | awk -F';' '{print $49}')
445445
DISK_IOPS=$(awk -v a="$DISK_IOPS_R" -v b="$DISK_IOPS_W" 'BEGIN { print a + b }')
@@ -477,14 +477,14 @@ function dd_test {
477477
while [ $I -lt 3 ]
478478
do
479479
# write test using dd, "direct" flag is used to test direct I/O for data being stored to disk
480-
DISK_WRITE_TEST=$(dd if=/dev/zero of=$DISK_PATH/$DATE.test bs=64k count=16k oflag=direct |& grep copied | awk '{ print $(NF-1) " " $(NF)}')
480+
DISK_WRITE_TEST=$(dd if=/dev/zero of="$DISK_PATH/$DATE.test" bs=64k count=16k oflag=direct |& grep copied | awk '{ print $(NF-1) " " $(NF)}')
481481
VAL=$(echo $DISK_WRITE_TEST | cut -d " " -f 1)
482482
[[ "$DISK_WRITE_TEST" == *"GB"* ]] && VAL=$(awk -v a="$VAL" 'BEGIN { print a * 1000 }')
483483
DISK_WRITE_TEST_RES+=( "$DISK_WRITE_TEST" )
484484
DISK_WRITE_TEST_AVG=$(awk -v a="$DISK_WRITE_TEST_AVG" -v b="$VAL" 'BEGIN { print a + b }')
485485

486486
# read test using dd using the 1G file written during the write test
487-
DISK_READ_TEST=$(dd if=$DISK_PATH/$DATE.test of=/dev/null bs=8k |& grep copied | awk '{ print $(NF-1) " " $(NF)}')
487+
DISK_READ_TEST=$(dd if="$DISK_PATH/$DATE.test" of=/dev/null bs=8k |& grep copied | awk '{ print $(NF-1) " " $(NF)}')
488488
VAL=$(echo $DISK_READ_TEST | cut -d " " -f 1)
489489
[[ "$DISK_READ_TEST" == *"GB"* ]] && VAL=$(awk -v a="$VAL" 'BEGIN { print a * 1000 }')
490490
DISK_READ_TEST_RES+=( "$DISK_READ_TEST" )
@@ -515,7 +515,7 @@ elif [ -z "$SKIP_FIO" ]; then
515515
for pathls in $(df -Th | awk '{print $7}' | tail -n +2)
516516
do
517517
if [[ "${PWD##$pathls}" != "${PWD}" ]]; then
518-
poss+=($pathls)
518+
poss+=("$pathls")
519519
fi
520520
done
521521

@@ -558,24 +558,24 @@ elif [ -z "$SKIP_FIO" ]; then
558558

559559
# create temp directory to store disk write/read test files
560560
DISK_PATH=$YABS_PATH/disk
561-
mkdir -p $DISK_PATH
561+
mkdir -p "$DISK_PATH"
562562

563563
if [[ -z "$PREFER_BIN" && ! -z "$LOCAL_FIO" ]]; then # local fio has been detected, use instead of pre-compiled binary
564564
FIO_CMD=fio
565565
else
566566
# download fio binary
567567
if [[ ! -z $LOCAL_CURL ]]; then
568-
curl -s --connect-timeout 5 --retry 5 --retry-delay 0 https://raw.githubusercontent.com/masonr/yet-another-bench-script/master/bin/fio/fio_$ARCH -o $DISK_PATH/fio
568+
curl -s --connect-timeout 5 --retry 5 --retry-delay 0 https://raw.githubusercontent.com/masonr/yet-another-bench-script/master/bin/fio/fio_$ARCH -o "$DISK_PATH/fio"
569569
else
570-
wget -q -T 5 -t 5 -w 0 https://raw.githubusercontent.com/masonr/yet-another-bench-script/master/bin/fio/fio_$ARCH -O $DISK_PATH/fio
570+
wget -q -T 5 -t 5 -w 0 https://raw.githubusercontent.com/masonr/yet-another-bench-script/master/bin/fio/fio_$ARCH -O "$DISK_PATH/fio"
571571
fi
572572

573573
if [ ! -f "$DISK_PATH/fio" ]; then # ensure fio binary download successfully
574574
echo -en "\r\033[0K"
575575
echo -e "Fio binary download failed. Running dd test as fallback...."
576576
DD_FALLBACK=True
577577
else
578-
chmod +x $DISK_PATH/fio
578+
chmod +x "$DISK_PATH/fio"
579579
FIO_CMD=$DISK_PATH/fio
580580
fi
581581
fi
@@ -678,7 +678,7 @@ function iperf_test {
678678
# run the iperf test sending data from the host to the iperf server; includes
679679
# a timeout of 15s in case the iperf server is not responding; uses 8 parallel
680680
# threads for the network test
681-
IPERF_RUN_SEND="$(timeout 15 $IPERF_CMD $FLAGS -c $URL -p $PORT -P 8 2> /dev/null)"
681+
IPERF_RUN_SEND="$(timeout 15 $IPERF_CMD $FLAGS -c "$URL" -p $PORT -P 8 2> /dev/null)"
682682
# check if iperf exited cleanly and did not return an error
683683
if [[ "$IPERF_RUN_SEND" == *"receiver"* && "$IPERF_RUN_SEND" != *"error"* ]]; then
684684
# test did not result in an error, parse speed result
@@ -706,7 +706,7 @@ function iperf_test {
706706
# run the iperf test receiving data from the iperf server to the host; includes
707707
# a timeout of 15s in case the iperf server is not responding; uses 8 parallel
708708
# threads for the network test
709-
IPERF_RUN_RECV="$(timeout 15 $IPERF_CMD $FLAGS -c $URL -p $PORT -P 8 -R 2> /dev/null)"
709+
IPERF_RUN_RECV="$(timeout 15 $IPERF_CMD $FLAGS -c "$URL" -p $PORT -P 8 -R 2> /dev/null)"
710710
# check if iperf exited cleanly and did not return an error
711711
if [[ "$IPERF_RUN_RECV" == *"receiver"* && "$IPERF_RUN_RECV" != *"error"* ]]; then
712712
# test did not result in an error, parse speed result
@@ -779,19 +779,19 @@ if [ -z "$SKIP_IPERF" ]; then
779779
else
780780
# create a temp directory to house the required iperf binary and library
781781
IPERF_PATH=$YABS_PATH/iperf
782-
mkdir -p $IPERF_PATH
782+
mkdir -p "$IPERF_PATH"
783783

784784
# download iperf3 binary
785785
if [[ ! -z $LOCAL_CURL ]]; then
786-
curl -s --connect-timeout 5 --retry 5 --retry-delay 0 https://raw.githubusercontent.com/masonr/yet-another-bench-script/master/bin/iperf/iperf3_$ARCH -o $IPERF_PATH/iperf3
786+
curl -s --connect-timeout 5 --retry 5 --retry-delay 0 https://raw.githubusercontent.com/masonr/yet-another-bench-script/master/bin/iperf/iperf3_$ARCH -o "$IPERF_PATH/iperf3"
787787
else
788-
wget -q -T 5 -t 5 -w 0 https://raw.githubusercontent.com/masonr/yet-another-bench-script/master/bin/iperf/iperf3_$ARCH -O $IPERF_PATH/iperf3
788+
wget -q -T 5 -t 5 -w 0 https://raw.githubusercontent.com/masonr/yet-another-bench-script/master/bin/iperf/iperf3_$ARCH -O "$IPERF_PATH/iperf3"
789789
fi
790790

791791
if [ ! -f "$IPERF_PATH/iperf3" ]; then # ensure iperf3 binary downloaded successfully
792792
IPERF_DL_FAIL=True
793793
else
794-
chmod +x $IPERF_PATH/iperf3
794+
chmod +x "$IPERF_PATH/iperf3"
795795
IPERF_CMD=$IPERF_PATH/iperf3
796796
fi
797797
fi
@@ -850,7 +850,7 @@ function launch_geekbench {
850850

851851
# create a temp directory to house all geekbench files
852852
GEEKBENCH_PATH=$YABS_PATH/geekbench_$VERSION
853-
mkdir -p $GEEKBENCH_PATH
853+
mkdir -p "$GEEKBENCH_PATH"
854854

855855
GB_URL=""
856856
GB_CMD=""
@@ -893,14 +893,14 @@ function launch_geekbench {
893893
GEEKBENCH_PATH=$(dirname "$(command -v "$GB_CMD")")
894894
else
895895
# download the desired Geekbench tarball and extract to geekbench temp directory
896-
$DL_CMD $GB_URL | tar xz --strip-components=1 -C $GEEKBENCH_PATH &>/dev/null
896+
$DL_CMD $GB_URL | tar xz --strip-components=1 -C "$GEEKBENCH_PATH" &>/dev/null
897897
fi
898898

899899
# unlock if license file detected
900-
test -f "geekbench.license" && $GEEKBENCH_PATH/$GB_CMD --unlock $(cat geekbench.license) > /dev/null 2>&1
900+
test -f "geekbench.license" && "$GEEKBENCH_PATH/$GB_CMD" --unlock $(cat geekbench.license) > /dev/null 2>&1
901901

902902
# run the Geekbench test and grep the test results URL given at the end of the test
903-
GEEKBENCH_TEST=$($GEEKBENCH_PATH/$GB_CMD --upload 2>/dev/null | grep "https://browser")
903+
GEEKBENCH_TEST=$("$GEEKBENCH_PATH/$GB_CMD" --upload 2>/dev/null | grep "https://browser")
904904

905905
# ensure the test ran successfully
906906
if [ -z "$GEEKBENCH_TEST" ]; then
@@ -969,7 +969,7 @@ fi
969969

970970
# finished all tests, clean up all YABS files and exit
971971
echo -e
972-
rm -rf $YABS_PATH
972+
rm -rf "$YABS_PATH"
973973

974974
YABS_END_TIME=$(date +%s)
975975

@@ -1000,7 +1000,7 @@ if [[ ! -z $JSON ]]; then
10001000

10011001
# write json results to file
10021002
if [[ $JSON = *w* ]]; then
1003-
echo $JSON_RESULT > $JSON_FILE
1003+
echo $JSON_RESULT > "$JSON_FILE"
10041004
fi
10051005

10061006
# send json results

0 commit comments

Comments
 (0)