Skip to content

Commit 5017be7

Browse files
yuta-hayamaMic92
authored andcommitted
Add test to set interpreter of same name
1 parent 0a64a88 commit 5017be7

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

tests/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ src_TESTS = \
5252
overlapping-segments-after-rounding.sh \
5353
shared-rpath.sh \
5454
short-first-segment.sh \
55-
empty-note.sh
55+
empty-note.sh \
56+
set-interpreter-same.sh
5657

5758
build_TESTS = \
5859
$(no_rpath_arch_TESTS)

tests/set-interpreter-same.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#! /bin/sh -e
2+
SCRATCH=scratch/$(basename "$0" .sh)
3+
4+
./simple
5+
6+
curInterpreter=$(../src/patchelf --print-interpreter ./simple)
7+
echo "current interpreter is $curInterpreter"
8+
9+
rm -rf "${SCRATCH}"
10+
mkdir -p "${SCRATCH}"
11+
12+
cp simple "${SCRATCH}"/
13+
14+
echo "set the same interpreter as the current one"
15+
before_checksum=$(sha256sum ${SCRATCH}/simple)
16+
../src/patchelf --set-interpreter "${curInterpreter}" "${SCRATCH}/simple"
17+
after_checksum=$(sha256sum ${SCRATCH}/simple)
18+
19+
if [ "$before_checksum" != "$after_checksum" ]; then
20+
echo "--set-interpreter should be NOP, but the file has been changed."
21+
exit 1
22+
fi
23+
24+
${SCRATCH}/simple
25+
26+
dummyInterpreter="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
27+
28+
echo "set the dummy interpreter"
29+
before_checksum=$(sha256sum ${SCRATCH}/simple)
30+
../src/patchelf --set-interpreter "${dummyInterpreter}" "${SCRATCH}/simple"
31+
after_checksum=$(sha256sum ${SCRATCH}/simple)
32+
33+
if [ "$before_checksum" = "$after_checksum" ]; then
34+
echo "--set-interpreter should be run, but the file has not been changed."
35+
exit 1
36+
fi
37+
38+
if "${SCRATCH}/simple"; then
39+
echo "simple works, but it shouldn't"
40+
exit 1
41+
fi
42+
43+
echo "set the same interpreter as the current one"
44+
before_checksum=$(sha256sum ${SCRATCH}/simple)
45+
../src/patchelf --set-interpreter "${dummyInterpreter}" "${SCRATCH}/simple"
46+
after_checksum=$(sha256sum ${SCRATCH}/simple)
47+
48+
if [ "$before_checksum" != "$after_checksum" ]; then
49+
echo "--set-interpreter should be NOP, but the file has been changed."
50+
exit 1
51+
fi
52+
53+
if "${SCRATCH}/simple"; then
54+
echo "simple works, but it shouldn't"
55+
exit 1
56+
fi

0 commit comments

Comments
 (0)