|
| 1 | +#! /bin/sh -e |
| 2 | + |
| 3 | +PATCHELF=$(readlink -f "../src/patchelf") |
| 4 | +SCRATCH="scratch/$(basename "$0" .sh)" |
| 5 | +READELF=${READELF:-readelf} |
| 6 | + |
| 7 | +LIB_NAME="${PWD}/libshared-rpath.so" |
| 8 | + |
| 9 | +rm -rf "${SCRATCH}" |
| 10 | +mkdir -p "${SCRATCH}" |
| 11 | +cd "${SCRATCH}" |
| 12 | + |
| 13 | +has_x() { |
| 14 | + strings "$1" | grep -c "XXXXXXXX" |
| 15 | +} |
| 16 | + |
| 17 | +nm -D "${LIB_NAME}" | grep a_symbol_name |
| 18 | +previous_cnt="$(strings "${LIB_NAME}" | grep -c a_symbol_name)" |
| 19 | + |
| 20 | +echo "#### Number of a_symbol_name strings in the library: $previous_cnt" |
| 21 | + |
| 22 | +echo "#### Rename the rpath to something larger than the original" |
| 23 | +# Pathelf should detect that the rpath string is shared with the symbol name string and avoid |
| 24 | +# tainting the string with Xs |
| 25 | +"${PATCHELF}" --set-rpath a_very_big_rpath_that_is_larger_than_original --output liblarge-rpath.so "${LIB_NAME}" |
| 26 | + |
| 27 | +echo "#### Checking symbol is still there" |
| 28 | +nm -D liblarge-rpath.so | grep a_symbol_name |
| 29 | + |
| 30 | +echo "#### Checking there are no Xs" |
| 31 | +[ "$(has_x liblarge-rpath.so)" -eq 0 ] || exit 1 |
| 32 | + |
| 33 | +current_cnt="$(strings liblarge-rpath.so | grep -c a_symbol_name)" |
| 34 | +echo "#### Number of a_symbol_name strings in the modified library: $current_cnt" |
| 35 | +[ "$current_cnt" -eq "$previous_cnt" ] || exit 1 |
| 36 | + |
| 37 | +echo "#### Rename the rpath to something shorter than the original" |
| 38 | +# Pathelf should detect that the rpath string is shared with the symbol name string and avoid |
| 39 | +# overwriting the existing string |
| 40 | +"${PATCHELF}" --set-rpath shrt_rpth --output libshort-rpath.so "${LIB_NAME}" |
| 41 | + |
| 42 | +echo "#### Checking symbol is still there" |
| 43 | +nm -D libshort-rpath.so | grep a_symbol_name |
| 44 | + |
| 45 | +echo "#### Number of a_symbol_name strings in the modified library: $current_cnt" |
| 46 | +current_cnt="$(strings libshort-rpath.so | grep -c a_symbol_name)" |
| 47 | +[ "$current_cnt" -eq "$previous_cnt" ] || exit 1 |
| 48 | + |
| 49 | +echo "#### Now liblarge-rpath.so should have its own rpath, so it should be allowed to taint it" |
| 50 | +"${PATCHELF}" --set-rpath a_very_big_rpath_that_is_larger_than_original__even_larger --output liblarge-rpath2.so liblarge-rpath.so |
| 51 | +[ "$(has_x liblarge-rpath2.so)" -eq 1 ] || exit 1 |
0 commit comments