Skip to content

Commit

Permalink
Add stress test to patch all binaries in the machine
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoguim committed Mar 11, 2023
1 parent 27cbc89 commit 5bd7b7a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: Publish
on:
workflow_dispatch:
inputs:
enable_stress_test:
description: "Run pachelf on all binaries in the image"
type: boolean
default: false
pull_request:
push:
branches:
Expand Down Expand Up @@ -89,7 +95,7 @@ jobs:
rm -f dist/*
cd patchelf-*
./configure --prefix /patchelf
make check || (cat tests/test-suite.log; exit 1)
make check STRESS=${{ inputs.enable_stress_test }} || (cat tests/test-suite.log; exit 1)
make install-strip
cd -
tar -czf ./dist/patchelf-\$(cat patchelf-*/version)-\$(uname -m).tar.gz -C /patchelf .
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ src_TESTS = \
modify-execstack.sh \
rename-dynamic-symbols.sh \
overlapping-segments-after-rounding.sh \
stress.sh \
empty-note.sh

build_TESTS = \
Expand Down
45 changes: 45 additions & 0 deletions tests/stress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#! /bin/sh -e

[ "$STRESS" = "1" ] || exit 0

SCRATCH=scratch/$(basename "$0" .sh)
PATCHELF=$(readlink -f "../src/patchelf")

rm -rf "${SCRATCH}"
mkdir -p "${SCRATCH}"
cd "${SCRATCH}"

for lib in /usr/lib*/*.so* /usr/bin/* /usr/libexec/*
do
if file "$lib" | grep -q -e "ELF.*dynamically"
then
echo "==============================================================="
echo "#### Copying"
echo "$lib"
echo "$(file $lib)"
blib="$(basename "$lib")"
cp "$lib" "$blib"
echo "#### chmod"
chmod +w "$blib"

echo "#### readelf before"
readelf -L "$blib" > /dev/null 2> re_before || echo
echo "#### ldd before"
ldd "$blib" | sed 's/0x.*//g' > ldd_before

echo "#### get rpath"
new_rpath="$(${PATCHELF} --print-rpath "$blib"):XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "#### new rpath: $new_rpath"
${PATCHELF} --force-rpath --set-rpath "$new_rpath" "$blib"

echo "#### readelf after"
readelf -L "$blib" > /dev/null 2> re_after || echo
echo "#### ldd after"
ldd "$blib" | sed 's/0x.*//g' > ldd_after

diff re_before re_after
diff ldd_before ldd_after

rm "$blib"
fi
done

0 comments on commit 5bd7b7a

Please sign in to comment.