From d5c4124a0bc3317cd20195ee00aed97b5489c5bf Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Tue, 25 May 2021 23:17:41 +0200 Subject: [PATCH] Make sure to compare canonical paths Absolute paths do not have to be canonical. For instance, .../a/../AppDir may be equivalent to .../AppDir, however the current implementation would not match them. --- src/core/appdir.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/appdir.cpp b/src/core/appdir.cpp index 5e46a72..e499b8f 100644 --- a/src/core/appdir.cpp +++ b/src/core/appdir.cpp @@ -830,27 +830,27 @@ namespace linuxdeploy { // TODO: quite similar to deployDependenciesForExistingFiles... maybe they should be merged or use each other bool AppDir::deployDependenciesOnlyForElfFile(const boost::filesystem::path& elfFilePath, bool failSilentForNonElfFile) { // preconditions: file must be an ELF one, and file must be contained in the AppDir - const auto absoluteElfFilePath = bf::absolute(elfFilePath); + const auto canonicalElfFilePath = bf::canonical(elfFilePath); // can't bundle directories - if (!bf::is_regular_file(absoluteElfFilePath)) { - ldLog() << LD_DEBUG << "Skipping non-file directory entry:" << absoluteElfFilePath << std::endl; + if (!bf::is_regular_file(canonicalElfFilePath)) { + ldLog() << LD_DEBUG << "Skipping non-file directory entry:" << canonicalElfFilePath << std::endl; return false; } - // to do a proper prefix check, we need a proper absolute path for the AppDir - const auto absoluteAppDirPath = bf::absolute(this->path()); - ldLog() << LD_DEBUG << "absolute AppDir path:" << absoluteAppDirPath << std::endl; + // to do a proper prefix check, we need a proper absolute canonical path for the AppDir + const auto canonicalAppDirPath = bf::canonical(this->path()); + ldLog() << LD_DEBUG << "absolute canonical AppDir path:" << canonicalAppDirPath << std::endl; // a fancy way to check STL strings for prefixes is to "ab"use rfind - if (absoluteElfFilePath.string().rfind(absoluteAppDirPath.string()) != 0) { - ldLog() << LD_ERROR << "File" << absoluteElfFilePath << "is not contained in AppDir, its dependencies cannot be deployed into the AppDir" << std::endl; + if (canonicalElfFilePath.string().rfind(canonicalAppDirPath.string()) != 0) { + ldLog() << LD_ERROR << "File" << canonicalElfFilePath << "is not contained in AppDir, its dependencies cannot be deployed into the AppDir" << std::endl; return false; } // make sure we have an ELF file try { - elf::ElfFile(absoluteElfFilePath.string()); + elf::ElfFile(canonicalElfFilePath.string()); } catch (const elf::ElfFileParseError& e) { auto level = LD_ERROR; @@ -858,7 +858,7 @@ namespace linuxdeploy { level = LD_WARNING; } - ldLog() << level << "Not an ELF file:" << absoluteElfFilePath << std::endl; + ldLog() << level << "Not an ELF file:" << canonicalElfFilePath << std::endl; return failSilentForNonElfFile; } @@ -867,7 +867,7 @@ namespace linuxdeploy { ldLog() << "Deploying dependencies for ELF file in AppDir:" << elfFilePath << std::endl; // bundle dependencies - if (!d->deployElfDependencies(absoluteElfFilePath)) + if (!d->deployElfDependencies(canonicalElfFilePath)) return false; // set rpath correctly @@ -877,7 +877,7 @@ namespace linuxdeploy { const auto rpath = PrivateData::calculateRelativeRPath(elfFilePath.parent_path(), rpathDestination); ldLog() << LD_DEBUG << "Calculated rpath:" << rpath << std::endl; - d->setElfRPathOperations[absoluteElfFilePath] = rpath; + d->setElfRPathOperations[canonicalElfFilePath] = rpath; return true; }