Skip to content

Commit 265b31a

Browse files
bors[bot]brenoguim
andauthored
Merge #478
478: Run shellcheck on all tests r=Mic92 a=brenoguim Co-authored-by: Breno Rodrigues Guimaraes <[email protected]>
2 parents 27cbc89 + 3710a70 commit 265b31a

File tree

9 files changed

+46
-41
lines changed

9 files changed

+46
-41
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ on:
33
pull_request:
44
push:
55
jobs:
6+
shellcheck:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- run: shellcheck tests/*.sh
611
nix:
712
runs-on: ubuntu-latest
813
steps:

tests/endianness.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ for arch in ppc64 ppc64le; do
66
rm -rf "${SCRATCH}"
77
mkdir -p "${SCRATCH}"
88

9-
cp "${srcdir}/endianness/${arch}/main" "${srcdir}/endianness/${arch}/libtest.so" "${SCRATCH}/"
9+
cp "${srcdir:?}/endianness/${arch}/main" "${srcdir}/endianness/${arch}/libtest.so" "${SCRATCH}/"
1010

1111
rpath="${PWD}/${SCRATCH}"
1212

tests/modify-execstack.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#! /bin/sh -e
2-
SCRATCH=scratch/$(basename $0 .sh)
2+
SCRATCH=scratch/$(basename "$0" .sh)
33
PATCHELF=$(readlink -f "../src/patchelf")
44

5-
rm -rf ${SCRATCH}
6-
mkdir -p ${SCRATCH}
5+
rm -rf "${SCRATCH}"
6+
mkdir -p "${SCRATCH}"
77

8-
cp simple ${SCRATCH}/
9-
cp simple-execstack ${SCRATCH}/
10-
cp libsimple.so ${SCRATCH}/
11-
cp libsimple-execstack.so ${SCRATCH}/
8+
cp simple "${SCRATCH}"/
9+
cp simple-execstack "${SCRATCH}"/
10+
cp libsimple.so "${SCRATCH}"/
11+
cp libsimple-execstack.so "${SCRATCH}"/
1212

13-
cd ${SCRATCH}
13+
cd "${SCRATCH}"
1414

1515

1616
## simple

tests/no-rpath-pie-powerpc.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ set -x
33
SCRATCH=scratch/no-rpath-pie-powerpc
44
READELF=${READELF:-readelf}
55

6-
no_rpath_bin="${srcdir}/no-rpath-prebuild/no-rpath-pie-powerpc"
6+
no_rpath_bin="${srcdir:?}/no-rpath-prebuild/no-rpath-pie-powerpc"
77

8-
if [ ! -f $no_rpath_bin ]; then
9-
echo "no 'no-rpath' binary for '$ARCH' in '${srcdir}/no-rpath-prebuild'"
8+
if [ ! -f "$no_rpath_bin" ]; then
9+
echo "no 'no-rpath' binary for '$ARCH' in '${srcdir:?}/no-rpath-prebuild'"
1010
exit 1
1111
fi
1212

1313
rm -rf ${SCRATCH}
1414
mkdir -p ${SCRATCH}
1515

16-
cp $no_rpath_bin ${SCRATCH}/no-rpath
16+
cp "$no_rpath_bin" ${SCRATCH}/no-rpath
1717

1818
oldRPath=$(../src/patchelf --print-rpath ${SCRATCH}/no-rpath)
1919
if test -n "$oldRPath"; then exit 1; fi
@@ -30,7 +30,7 @@ fi
3030
# Tests for powerpc PIE endianness regressions
3131
readelfData=$(${READELF} -l ${SCRATCH}/no-rpath 2>&1)
3232

33-
if [ $(echo "$readelfData" | grep "PHDR" | wc -l) != 1 ]; then
33+
if [ "$(echo "$readelfData" | grep -c "PHDR")" != 1 ]; then
3434
# Triggered if PHDR errors appear on stderr
3535
echo "Unexpected number of occurences of PHDR in readelf results"
3636
exit 1

tests/no-rpath-prebuild.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ if [ -z "$ARCH" ] || [ "$ARCH" = prebuild ] ; then
1414
exit 1
1515
fi
1616

17-
no_rpath_bin="${srcdir}/no-rpath-prebuild/no-rpath-$ARCH"
17+
no_rpath_bin="${srcdir:?}/no-rpath-prebuild/no-rpath-$ARCH"
1818

1919
if [ ! -f "$no_rpath_bin" ]; then
20-
echo "no 'no-rpath' binary for '$ARCH' in '${srcdir}/no-rpath-prebuild'"
20+
echo "no 'no-rpath' binary for '$ARCH' in '${srcdir:?}/no-rpath-prebuild'"
2121
exit 1
2222
fi
2323

tests/overlapping-segments-after-rounding.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if test "$(uname -i)" = x86_64 && test "$(uname)" = Linux; then
1010
rm -rf "${SCRATCH}"
1111
mkdir -p "${SCRATCH}"
1212

13-
cp "${srcdir}/${EXEC_NAME}" "${SCRATCH}/"
13+
cp "${srcdir:?}/${EXEC_NAME}" "${SCRATCH}/"
1414
cd "${SCRATCH}"
1515

1616
${PATCHELF} --force-rpath --remove-rpath --output modified1 "${EXEC_NAME}"

tests/phdr-corruption.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cp "${SONAME}" "${SCRATCH}"
1515
# Check for PT_PHDR entry VirtAddr corruption
1616
readelfData=$(${READELF} -l "${SCRATCH_SO}" 2>&1)
1717

18-
if [ "$(echo "$readelfData" | grep "PHDR" | wc -l)" != 1 ]; then
18+
if [ "$(echo "$readelfData" | grep -c "PHDR")" != 1 ]; then
1919
# Triggered if PHDR errors appear on stderr
2020
echo "ERROR: Unexpected number of occurences of PHDR in readelf results!"
2121
exit 1

tests/print-execstack.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#! /bin/sh -e
2-
SCRATCH=scratch/$(basename $0 .sh)
2+
SCRATCH=scratch/$(basename "$0" .sh)
33
PATCHELF=$(readlink -f "../src/patchelf")
44

5-
rm -rf ${SCRATCH}
6-
mkdir -p ${SCRATCH}
5+
rm -rf "${SCRATCH}"
6+
mkdir -p "${SCRATCH}"
77

8-
cp simple ${SCRATCH}/
9-
cp simple-execstack ${SCRATCH}/
8+
cp simple "${SCRATCH}"/
9+
cp simple-execstack "${SCRATCH}"/
1010

11-
cd ${SCRATCH}
11+
cd "${SCRATCH}"
1212

1313
if ! ${PATCHELF} --print-execstack simple | grep -q 'execstack: -'; then
1414
echo "wrong execstack detection"

tests/rename-dynamic-symbols.sh

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/bin/sh -e
2-
SCRATCH=scratch/$(basename $0 .sh)
2+
SCRATCH=scratch/$(basename "$0" .sh)
33
PATCHELF=$(readlink -f "../src/patchelf")
44

5-
rm -rf ${SCRATCH}
6-
mkdir -p ${SCRATCH}
5+
rm -rf "${SCRATCH}"
6+
mkdir -p "${SCRATCH}"
77

88
full_main_name="${PWD}/many-syms-main"
99
full_lib_name="${PWD}/libmany-syms.so"
10-
chmod -w $full_lib_name $full_main_name
10+
chmod -w "$full_lib_name" "$full_main_name"
1111

1212
suffix="_special_suffix"
1313

14-
cd ${SCRATCH}
14+
cd "${SCRATCH}"
1515

1616
###############################################################################
1717
# Test that all symbols in the dynamic symbol table will have the expected
@@ -20,16 +20,16 @@ cd ${SCRATCH}
2020
###############################################################################
2121

2222
list_symbols() {
23-
nm -D $@ | awk '{ print $NF }' | sed '/^ *$/d'
23+
nm -D "$@" | awk '{ print $NF }' | sed '/^ *$/d'
2424
}
2525

26-
list_symbols $full_lib_name | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map
27-
list_symbols $full_lib_name | cut -d@ -f1 | sort -u | awk "{printf \"%s${suffix} %s\n\",\$1,\$1}" > rmap
26+
list_symbols "$full_lib_name" | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map
27+
list_symbols "$full_lib_name" | cut -d@ -f1 | sort -u | awk "{printf \"%s${suffix} %s\n\",\$1,\$1}" > rmap
2828

29-
${PATCHELF} --rename-dynamic-symbols map --output libmapped.so $full_lib_name
29+
${PATCHELF} --rename-dynamic-symbols map --output libmapped.so "$full_lib_name"
3030
${PATCHELF} --rename-dynamic-symbols rmap --output libreversed.so libmapped.so
3131

32-
list_symbols $full_lib_name | sort > orig_syms
32+
list_symbols "$full_lib_name" | sort > orig_syms
3333
list_symbols libmapped.so | sort > map_syms
3434
list_symbols libreversed.so | sort > rev_syms
3535

@@ -47,10 +47,10 @@ diff orig_syms map_syms_r > diff_orig_syms_map_syms_r || exit 1
4747
###############################################################################
4848

4949
print_relocation_table() {
50-
readelf -W -r $1 | awk '{ printf "%s\n",$5 }' | cut -f1 -d@
50+
readelf -W -r "$1" | awk '{ printf "%s\n",$5 }' | cut -f1 -d@
5151
}
5252

53-
print_relocation_table $full_lib_name > orig_rel
53+
print_relocation_table "$full_lib_name" > orig_rel
5454
print_relocation_table libmapped.so > map_rel
5555
print_relocation_table libreversed.so > rev_rel
5656

@@ -69,19 +69,19 @@ diff orig_rel map_rel_r > diff_orig_rel_map_rel_r || exit 1
6969
###############################################################################
7070

7171
echo "# Create the map"
72-
list_symbols --defined-only $full_lib_name | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map
72+
list_symbols --defined-only "$full_lib_name" | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map
7373

7474
echo "# Copy all dependencies"
7575
mkdir env
7676
cd env
77-
cp $full_lib_name $full_main_name .
77+
cp "$full_lib_name" "$full_main_name" .
7878

7979
echo "# Apply renaming"
80-
chmod +w *
81-
${PATCHELF} --rename-dynamic-symbols ../map *
80+
chmod +w ./*
81+
${PATCHELF} --rename-dynamic-symbols ../map ./*
8282

8383
echo "# Run the patched tool and libraries"
84-
env LD_BIND_NOW=1 LD_LIBRARY_PATH=${PWD} ./many-syms-main
84+
env LD_BIND_NOW=1 LD_LIBRARY_PATH="${PWD}" ./many-syms-main
8585

8686
# Test that other switches still work when --rename-dynamic-symbols has no effect
8787
echo "SYMBOL_THAT_DOESNT_EXIST ANOTHER_NAME" > map

0 commit comments

Comments
 (0)