From 476b57b08abf6a8dab17159f70a3c2c2ef727c22 Mon Sep 17 00:00:00 2001 From: 48cf <32851089+48cf@users.noreply.github.com> Date: Sun, 28 Jan 2024 01:33:26 +0100 Subject: [PATCH] options/rtdl: Drop trailing slashes from paths in LD_LIBRARY_PATH --- options/rtdl/generic/linker.cpp | 2 +- options/rtdl/generic/main.cpp | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/options/rtdl/generic/linker.cpp b/options/rtdl/generic/linker.cpp index 62408f4b78..92ebadb8f0 100644 --- a/options/rtdl/generic/linker.cpp +++ b/options/rtdl/generic/linker.cpp @@ -235,7 +235,7 @@ SharedObject *ObjectRepository::requestObjectWithName(frg::string_view name, auto ldPath = (*libraryPaths)[i]; auto path = frg::string{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); diff --git a/options/rtdl/generic/main.cpp b/options/rtdl/generic/main.cpp index eb4a5923b7..6c58e301bd 100644 --- a/options/rtdl/generic/main.cpp +++ b/options/rtdl/generic/main.cpp @@ -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); } } @@ -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) {