Skip to content

Commit 890118e

Browse files
committed
Add a number of tests for binaries that used to crash patchelf
Most now error out nicely, as of 0.16, but some still cause a crash. Fix #132 Progress on #133 (have tests, failure remains) Fix #134 Progress on #135 (have test, failure remains)
1 parent 4c0bb4f commit 890118e

11 files changed

+95
-5
lines changed

tests/invalid-elf.sh

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,67 @@ TEST_CASES="invalid-shrstrtab-idx invalid-shrstrtab-size invalid-shrstrtab-zero
2121
# Issue #64 regression test. Test ELF provided by issue submitter.
2222
TEST_CASES=$TEST_CASES' invalid-phdr-issue-64'
2323

24+
# Issue #132 regression test. Test ELF provided by issue submitter.
25+
TEST_CASES=$TEST_CASES' invalid-shrink-rpath-issue-132'
26+
27+
# Issue #133 regression test. Test ELFs provided by issue submitter.
28+
set -x
29+
for i in $(seq 0 5); do
30+
# Not yet fixed!
31+
if [ "$i" == 3 ]; then continue; fi
32+
TEST_CASES=$TEST_CASES' invalid-strlen-issue-133-'$i
33+
done
34+
set +x
35+
36+
# Issue #134 regression test. Test ELFs provided by issue submitter.
37+
set -x
38+
for i in $(seq 0 1); do
39+
TEST_CASES=$TEST_CASES' invalid-null-ptr-issue-134-'$i
40+
done
41+
set +x
42+
43+
# Not yet fixed!
44+
# Issue #132 regression test. Test ELF provided by issue submitter.
45+
#TEST_CASES=$TEST_CASES' invalid-string-index-issue-135'
46+
47+
# Some ELFs are immediately recognized as invalid. Others, we need to
48+
# attempt an operation to notice the problem.
49+
50+
# shellcheck disable=SC2034
51+
invalid_shrstrtab_idx_CMDS=''
52+
# shellcheck disable=SC2034
53+
invalid_shrstrtab_size_CMDS=''
54+
# shellcheck disable=SC2034
55+
invalid_shrstrtab_zero_CMDS=''
56+
# shellcheck disable=SC2034
57+
invalid_shrstrtab_nonterm_CMDS=''
58+
# shellcheck disable=SC2034
59+
invalid_shdr_name_CMDS=''
60+
# shellcheck disable=SC2034
61+
invalid_phdr_offset_CMDS=''
62+
# shellcheck disable=SC2034
63+
invalid_phdr_issue_64_CMDS=''
64+
# shellcheck disable=SC2034
65+
invalid_shrink_rpath_issue_132_CMDS='--shrink-rpath'
66+
# shellcheck disable=SC2034
67+
invalid_strlen_issue_133_0_CMDS='--shrink-rpath'
68+
# shellcheck disable=SC2034
69+
invalid_strlen_issue_133_1_CMDS='--shrink-rpath'
70+
# shellcheck disable=SC2034
71+
invalid_strlen_issue_133_2_CMDS='--shrink-rpath'
72+
# shellcheck disable=SC2034
73+
invalid_strlen_issue_133_3_CMDS='--shrink-rpath'
74+
# shellcheck disable=SC2034
75+
invalid_strlen_issue_133_4_CMDS='--shrink-rpath'
76+
# shellcheck disable=SC2034
77+
invalid_strlen_issue_133_5_CMDS='--shrink-rpath'
78+
# shellcheck disable=SC2034
79+
invalid_null_ptr_issue_134_0_CMDS='--shrink-rpath'
80+
# shellcheck disable=SC2034
81+
invalid_null_ptr_issue_134_1_CMDS='--shrink-rpath'
82+
# shellcheck disable=SC2034
83+
invalid_string_index_issue_135_CMDS='--shrink-rpath'
84+
2485
# shellcheck disable=SC2034
2586
invalid_shrstrtab_idx_MSG='data region extends past file end'
2687
# shellcheck disable=SC2034
@@ -35,24 +96,53 @@ invalid_shdr_name_MSG='data region extends past file end'
3596
invalid_phdr_offset_MSG='data region extends past file end'
3697
# shellcheck disable=SC2034
3798
invalid_phdr_issue_64_MSG='program header table out of bounds'
99+
# shellcheck disable=SC2034
100+
invalid_shrink_rpath_issue_132_MSG='data region extends past file end'
101+
# shellcheck disable=SC2034
102+
invalid_strlen_issue_133_0_MSG='section name offset out of bounds'
103+
# shellcheck disable=SC2034
104+
invalid_strlen_issue_133_1_MSG='data region extends past file end'
105+
# shellcheck disable=SC2034
106+
invalid_strlen_issue_133_2_MSG='string table is not zero terminated'
107+
# shellcheck disable=SC2034
108+
invalid_strlen_issue_133_3_MSG='not sure yet'
109+
# shellcheck disable=SC2034
110+
invalid_strlen_issue_133_4_MSG='data region extends past file end'
111+
# shellcheck disable=SC2034
112+
invalid_strlen_issue_133_5_MSG='string table size is zero'
113+
# shellcheck disable=SC2034
114+
invalid_null_ptr_issue_134_0_MSG='no section headers'
115+
# shellcheck disable=SC2034
116+
invalid_null_ptr_issue_134_1_MSG='no section headers'
117+
# shellcheck disable=SC2034
118+
invalid_string_index_issue_135_MSG='no sure yet'
38119

39120
FAILED_TESTS=""
40121

41122
for tcase in $TEST_CASES; do
42123
if [ ! -r "$TEST_DIR/$tcase" ]; then
43-
echo "Cannot read test case: $tcase"
44-
exit 1
124+
echo "Cannot read test case: $tcase"
125+
exit 1
45126
fi
46127

47-
../src/patchelf --output /dev/null "$TEST_DIR/$tcase" && res=$? || res=$?
128+
var=$(echo "$tcase-CMDS" | tr '-' '_')
129+
cmds=
130+
eval "cmds=\${$var}"
131+
132+
# Want the word-splitting, no arrays in POSIX shell
133+
# shellcheck disable=SC2086
134+
../src/patchelf $cmds --output /dev/null "$TEST_DIR/$tcase" && res=$? || res=$?
48135
if killed_by_signal "$res"; then
49-
FAILED_TESTS="$FAILED_TESTS $tcase"
136+
FAILED_TESTS="$FAILED_TESTS $tcase"
50137
fi
51138

52139
var=$(echo "$tcase-MSG" | tr '-' '_')
53140
msg=
54141
eval "msg=\${$var}"
55-
../src/patchelf --output /dev/null "$TEST_DIR/$tcase" 2>&1 |
142+
143+
# Want the word-splitting, no arrays in POSIX shell
144+
# shellcheck disable=SC2086
145+
../src/patchelf $cmds --output /dev/null "$TEST_DIR/$tcase" 2>&1 |
56146
grep "$msg" >/dev/null 2>/dev/null
57147
done
58148

9.61 KB
Binary file not shown.
10.1 KB
Binary file not shown.
10.1 KB
Binary file not shown.
10.1 KB
Binary file not shown.
10.1 KB
Binary file not shown.
10.1 KB
Binary file not shown.
10.1 KB
Binary file not shown.
10.1 KB
Binary file not shown.
10.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)