Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/patchelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,19 @@ void ElfFile<ElfFileParamNames>::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<ElfFileParams>
void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op,
const std::vector<std::string> & allowedRpathPrefixes, std::string newRPath)
Expand Down Expand Up @@ -1474,14 +1487,15 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op,
debug("no RPATH to delete\n");
return;
}
zeroOutRpath(rpath);
removeRPath(shdrDynamic);
return;
}
case rpShrink: {
if (!rpath) {
debug("no RPATH to shrink\n");
return;
;}
}
newRPath = shrinkRPath(rpath, neededLibs, allowedRpathPrefixes);
break;
}
Expand Down Expand Up @@ -1511,17 +1525,10 @@ void ElfFile<ElfFileParamNames>::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;
Expand Down