Skip to content

Commit

Permalink
Merge pull request #971 from 48cf/master
Browse files Browse the repository at this point in the history
options/rtdl: Drop trailing slashes from paths in LD_LIBRARY_PATH
  • Loading branch information
qookei authored Jan 28, 2024
2 parents 6184a59 + 476b57b commit 0f39561
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion options/rtdl/generic/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ SharedObject *ObjectRepository::requestObjectWithName(frg::string_view name,
auto ldPath = (*libraryPaths)[i];
auto path = frg::string<MemoryAllocator>{getAllocator(), ldPath} + '/' + name;
if(logLdPath)
mlibc::infoLogger() << "rtdl: Trying to load " << name << " from ldpath " << ldPath << frg::endlog;
mlibc::infoLogger() << "rtdl: Trying to load " << name << " from ldpath " << ldPath << "/" << frg::endlog;
fd = tryToOpen(path.data());
if(fd >= 0) {
chosenPath = std::move(path);
Expand Down
25 changes: 20 additions & 5 deletions options/rtdl/generic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,23 @@ static void parseLibraryPaths(frg::string_view paths) {
s = paths.size();
}

libraryPaths->push_back(paths.sub_string(p, s - p));
auto ldPath = paths.sub_string(p, s - p);
p = s + 1;

if(ldPath.size() == 0)
continue;

if(ldPath.ends_with("/")) {
size_t i = ldPath.size() - 1;
while(i > 0 && ldPath[i] == '/')
i--;
ldPath = ldPath.sub_string(0, i + 1);
}

if(ldPath == "/")
ldPath = "";

libraryPaths->push_back(ldPath);
}
}

Expand Down Expand Up @@ -316,10 +331,10 @@ extern "C" void *interpreterMain(uintptr_t *entry_stack) {
aux++;

// Add default library paths
libraryPaths->push_back("/lib/");
libraryPaths->push_back("/lib64/");
libraryPaths->push_back("/usr/lib/");
libraryPaths->push_back("/usr/lib64/");
libraryPaths->push_back("/lib");
libraryPaths->push_back("/lib64");
libraryPaths->push_back("/usr/lib");
libraryPaths->push_back("/usr/lib64");

// Parse the actual vector.
while(true) {
Expand Down

0 comments on commit 0f39561

Please sign in to comment.