diff --git a/src/patchelf.cc b/src/patchelf.cc index 2bb84eb7..67aa172c 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -1415,6 +1415,19 @@ void ElfFile::removeRPath(Elf_Shdr & shdrDynamic) { this->rewriteSections(); } +/** Zeroes out the rpath string and returns its former length */ +size_t zeroOutRpath(char* rpath) +{ + /* Zero out the previous rpath to prevent retained dependencies in + Nix. */ + size_t rpathSize = 0; + if (rpath) { + rpathSize = strlen(rpath); + memset(rpath, 'X', rpathSize); + } + return rpathSize; +} + template void ElfFile::modifyRPath(RPathOp op, const std::vector & allowedRpathPrefixes, std::string newRPath) @@ -1474,6 +1487,7 @@ void ElfFile::modifyRPath(RPathOp op, debug("no RPATH to delete\n"); return; } + zeroOutRpath(rpath); removeRPath(shdrDynamic); return; } @@ -1481,7 +1495,7 @@ void ElfFile::modifyRPath(RPathOp op, if (!rpath) { debug("no RPATH to shrink\n"); return; - ;} + } newRPath = shrinkRPath(rpath, neededLibs, allowedRpathPrefixes); break; } @@ -1511,17 +1525,10 @@ void ElfFile::modifyRPath(RPathOp op, } changed = true; - /* Zero out the previous rpath to prevent retained dependencies in - Nix. */ - size_t rpathSize = 0; - if (rpath) { - rpathSize = strlen(rpath); - memset(rpath, 'X', rpathSize); - } + size_t rpathSize = zeroOutRpath(rpath); debug("new rpath is '%s'\n", newRPath.c_str()); - if (newRPath.size() <= rpathSize) { if (rpath) memcpy(rpath, newRPath.c_str(), newRPath.size() + 1); return;