From 8adc31ed7b30b689e50314c1c8a1842bc6e164af Mon Sep 17 00:00:00 2001 From: Breno Rodrigues Guimaraes Date: Sat, 11 Mar 2023 11:34:25 -0300 Subject: Fix all shellcheck issues --- tests/endianness.sh | 2 +- tests/modify-execstack.sh | 16 ++++++------- tests/no-rpath-pie-powerpc.sh | 10 ++++---- tests/no-rpath-prebuild.sh | 4 ++-- tests/overlapping-segments-after-rounding.sh | 2 +- tests/phdr-corruption.sh | 2 +- tests/print-execstack.sh | 12 +++++----- tests/rename-dynamic-symbols.sh | 34 ++++++++++++++-------------- 8 files changed, 41 insertions(+), 41 deletions(-) diff --git a/tests/endianness.sh b/tests/endianness.sh index fc2994b..41890f0 100755 --- a/tests/endianness.sh +++ b/tests/endianness.sh @@ -6,7 +6,7 @@ for arch in ppc64 ppc64le; do rm -rf "${SCRATCH}" mkdir -p "${SCRATCH}" - cp "${srcdir}/endianness/${arch}/main" "${srcdir}/endianness/${arch}/libtest.so" "${SCRATCH}/" + cp "${srcdir:?}/endianness/${arch}/main" "${srcdir}/endianness/${arch}/libtest.so" "${SCRATCH}/" rpath="${PWD}/${SCRATCH}" diff --git a/tests/modify-execstack.sh b/tests/modify-execstack.sh index 6baae48..01e45d8 100755 --- a/tests/modify-execstack.sh +++ b/tests/modify-execstack.sh @@ -1,16 +1,16 @@ #! /bin/sh -e -SCRATCH=scratch/$(basename $0 .sh) +SCRATCH=scratch/$(basename "$0" .sh) PATCHELF=$(readlink -f "../src/patchelf") -rm -rf ${SCRATCH} -mkdir -p ${SCRATCH} +rm -rf "${SCRATCH}" +mkdir -p "${SCRATCH}" -cp simple ${SCRATCH}/ -cp simple-execstack ${SCRATCH}/ -cp libsimple.so ${SCRATCH}/ -cp libsimple-execstack.so ${SCRATCH}/ +cp simple "${SCRATCH}"/ +cp simple-execstack "${SCRATCH}"/ +cp libsimple.so "${SCRATCH}"/ +cp libsimple-execstack.so "${SCRATCH}"/ -cd ${SCRATCH} +cd "${SCRATCH}" ## simple diff --git a/tests/no-rpath-pie-powerpc.sh b/tests/no-rpath-pie-powerpc.sh index 963797c..c2b50fe 100755 --- a/tests/no-rpath-pie-powerpc.sh +++ b/tests/no-rpath-pie-powerpc.sh @@ -3,17 +3,17 @@ set -x SCRATCH=scratch/no-rpath-pie-powerpc READELF=${READELF:-readelf} -no_rpath_bin="${srcdir}/no-rpath-prebuild/no-rpath-pie-powerpc" +no_rpath_bin="${srcdir:?}/no-rpath-prebuild/no-rpath-pie-powerpc" -if [ ! -f $no_rpath_bin ]; then - echo "no 'no-rpath' binary for '$ARCH' in '${srcdir}/no-rpath-prebuild'" +if [ ! -f "$no_rpath_bin" ]; then + echo "no 'no-rpath' binary for '$ARCH' in '${srcdir:?}/no-rpath-prebuild'" exit 1 fi rm -rf ${SCRATCH} mkdir -p ${SCRATCH} -cp $no_rpath_bin ${SCRATCH}/no-rpath +cp "$no_rpath_bin" ${SCRATCH}/no-rpath oldRPath=$(../src/patchelf --print-rpath ${SCRATCH}/no-rpath) if test -n "$oldRPath"; then exit 1; fi @@ -30,7 +30,7 @@ fi # Tests for powerpc PIE endianness regressions readelfData=$(${READELF} -l ${SCRATCH}/no-rpath 2>&1) -if [ $(echo "$readelfData" | grep "PHDR" | wc -l) != 1 ]; then +if [ "$(echo "$readelfData" | grep -c "PHDR")" != 1 ]; then # Triggered if PHDR errors appear on stderr echo "Unexpected number of occurences of PHDR in readelf results" exit 1 diff --git a/tests/no-rpath-prebuild.sh b/tests/no-rpath-prebuild.sh index 143c55c..aeeecf8 100755 --- a/tests/no-rpath-prebuild.sh +++ b/tests/no-rpath-prebuild.sh @@ -14,10 +14,10 @@ if [ -z "$ARCH" ] || [ "$ARCH" = prebuild ] ; then exit 1 fi -no_rpath_bin="${srcdir}/no-rpath-prebuild/no-rpath-$ARCH" +no_rpath_bin="${srcdir:?}/no-rpath-prebuild/no-rpath-$ARCH" if [ ! -f "$no_rpath_bin" ]; then - echo "no 'no-rpath' binary for '$ARCH' in '${srcdir}/no-rpath-prebuild'" + echo "no 'no-rpath' binary for '$ARCH' in '${srcdir:?}/no-rpath-prebuild'" exit 1 fi diff --git a/tests/overlapping-segments-after-rounding.sh b/tests/overlapping-segments-after-rounding.sh index d7c87b1..a2b5658 100755 --- a/tests/overlapping-segments-after-rounding.sh +++ b/tests/overlapping-segments-after-rounding.sh @@ -10,7 +10,7 @@ if test "$(uname -i)" = x86_64 && test "$(uname)" = Linux; then rm -rf "${SCRATCH}" mkdir -p "${SCRATCH}" - cp "${srcdir}/${EXEC_NAME}" "${SCRATCH}/" + cp "${srcdir:?}/${EXEC_NAME}" "${SCRATCH}/" cd "${SCRATCH}" ${PATCHELF} --force-rpath --remove-rpath --output modified1 "${EXEC_NAME}" diff --git a/tests/phdr-corruption.sh b/tests/phdr-corruption.sh index 4f6e901..274d6f1 100755 --- a/tests/phdr-corruption.sh +++ b/tests/phdr-corruption.sh @@ -15,7 +15,7 @@ cp "${SONAME}" "${SCRATCH}" # Check for PT_PHDR entry VirtAddr corruption readelfData=$(${READELF} -l "${SCRATCH_SO}" 2>&1) -if [ "$(echo "$readelfData" | grep "PHDR" | wc -l)" != 1 ]; then +if [ "$(echo "$readelfData" | grep -c "PHDR")" != 1 ]; then # Triggered if PHDR errors appear on stderr echo "ERROR: Unexpected number of occurences of PHDR in readelf results!" exit 1 diff --git a/tests/print-execstack.sh b/tests/print-execstack.sh index e34fad8..afd45a2 100755 --- a/tests/print-execstack.sh +++ b/tests/print-execstack.sh @@ -1,14 +1,14 @@ #! /bin/sh -e -SCRATCH=scratch/$(basename $0 .sh) +SCRATCH=scratch/$(basename "$0" .sh) PATCHELF=$(readlink -f "../src/patchelf") -rm -rf ${SCRATCH} -mkdir -p ${SCRATCH} +rm -rf "${SCRATCH}" +mkdir -p "${SCRATCH}" -cp simple ${SCRATCH}/ -cp simple-execstack ${SCRATCH}/ +cp simple "${SCRATCH}"/ +cp simple-execstack "${SCRATCH}"/ -cd ${SCRATCH} +cd "${SCRATCH}" if ! ${PATCHELF} --print-execstack simple | grep -q 'execstack: -'; then echo "wrong execstack detection" diff --git a/tests/rename-dynamic-symbols.sh b/tests/rename-dynamic-symbols.sh index dc33e1b..e6c1fba 100755 --- a/tests/rename-dynamic-symbols.sh +++ b/tests/rename-dynamic-symbols.sh @@ -1,17 +1,17 @@ #!/bin/sh -e -SCRATCH=scratch/$(basename $0 .sh) +SCRATCH=scratch/$(basename "$0" .sh) PATCHELF=$(readlink -f "../src/patchelf") -rm -rf ${SCRATCH} -mkdir -p ${SCRATCH} +rm -rf "${SCRATCH}" +mkdir -p "${SCRATCH}" full_main_name="${PWD}/many-syms-main" full_lib_name="${PWD}/libmany-syms.so" -chmod -w $full_lib_name $full_main_name +chmod -w "$full_lib_name" "$full_main_name" suffix="_special_suffix" -cd ${SCRATCH} +cd "${SCRATCH}" ############################################################################### # Test that all symbols in the dynamic symbol table will have the expected @@ -20,16 +20,16 @@ cd ${SCRATCH} ############################################################################### list_symbols() { - nm -D $@ | awk '{ print $NF }' | sed '/^ *$/d' + nm -D "$@" | awk '{ print $NF }' | sed '/^ *$/d' } -list_symbols $full_lib_name | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map -list_symbols $full_lib_name | cut -d@ -f1 | sort -u | awk "{printf \"%s${suffix} %s\n\",\$1,\$1}" > rmap +list_symbols "$full_lib_name" | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map +list_symbols "$full_lib_name" | cut -d@ -f1 | sort -u | awk "{printf \"%s${suffix} %s\n\",\$1,\$1}" > rmap -${PATCHELF} --rename-dynamic-symbols map --output libmapped.so $full_lib_name +${PATCHELF} --rename-dynamic-symbols map --output libmapped.so "$full_lib_name" ${PATCHELF} --rename-dynamic-symbols rmap --output libreversed.so libmapped.so -list_symbols $full_lib_name | sort > orig_syms +list_symbols "$full_lib_name" | sort > orig_syms list_symbols libmapped.so | sort > map_syms list_symbols libreversed.so | sort > rev_syms @@ -47,10 +47,10 @@ diff orig_syms map_syms_r > diff_orig_syms_map_syms_r || exit 1 ############################################################################### print_relocation_table() { - readelf -W -r $1 | awk '{ printf "%s\n",$5 }' | cut -f1 -d@ + readelf -W -r "$1" | awk '{ printf "%s\n",$5 }' | cut -f1 -d@ } -print_relocation_table $full_lib_name > orig_rel +print_relocation_table "$full_lib_name" > orig_rel print_relocation_table libmapped.so > map_rel print_relocation_table libreversed.so > rev_rel @@ -69,19 +69,19 @@ diff orig_rel map_rel_r > diff_orig_rel_map_rel_r || exit 1 ############################################################################### echo "# Create the map" -list_symbols --defined-only $full_lib_name | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map +list_symbols --defined-only "$full_lib_name" | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map echo "# Copy all dependencies" mkdir env cd env -cp $full_lib_name $full_main_name . +cp "$full_lib_name" "$full_main_name" . echo "# Apply renaming" -chmod +w * -${PATCHELF} --rename-dynamic-symbols ../map * +chmod +w ./* +${PATCHELF} --rename-dynamic-symbols ../map ./* echo "# Run the patched tool and libraries" -env LD_BIND_NOW=1 LD_LIBRARY_PATH=${PWD} ./many-syms-main +env LD_BIND_NOW=1 LD_LIBRARY_PATH="${PWD}" ./many-syms-main # Test that other switches still work when --rename-dynamic-symbols has no effect echo "SYMBOL_THAT_DOESNT_EXIST ANOTHER_NAME" > map -- cgit v1.2.1