From de3901853d49e7a607fc2bcdeb18e33875bce8ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 12 Sep 2021 10:26:13 +0200 Subject: [PATCH] fix setting empty rpath --- src/patchelf.cc | 2 +- tests/Makefile.am | 3 ++- tests/set-empty-rpath.sh | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100755 tests/set-empty-rpath.sh diff --git a/src/patchelf.cc b/src/patchelf.cc index 246496d5..4cc5e183 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -1500,7 +1500,7 @@ void ElfFile::modifyRPath(RPathOp op, debug("new rpath is '%s'\n", newRPath.c_str()); - if (newRPath.size() <= rpathSize) { + if (rpath && newRPath.size() <= rpathSize) { memcpy(rpath, newRPath.c_str(), newRPath.size() + 1); return; } diff --git a/tests/Makefile.am b/tests/Makefile.am index 38438b81..135ae4fb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -37,7 +37,8 @@ src_TESTS = \ no-gnu-hash.sh \ no-dynamic-section.sh \ args-from-file.sh \ - basic-flags.sh + basic-flags.sh \ + set-empty-rpath.sh build_TESTS = \ $(no_rpath_arch_TESTS) diff --git a/tests/set-empty-rpath.sh b/tests/set-empty-rpath.sh new file mode 100755 index 00000000..de846a27 --- /dev/null +++ b/tests/set-empty-rpath.sh @@ -0,0 +1,11 @@ +#! /bin/sh -e +SCRATCH=scratch/$(basename $0 .sh) + +rm -rf ${SCRATCH} +mkdir -p ${SCRATCH} + +cp simple ${SCRATCH}/simple + +../src/patchelf --force-rpath --set-rpath "" ${SCRATCH}/simple + +${SCRATCH}/simple