From 1e25f2b3db126f92e4fd7f59d95205c006df6844 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 9 Mar 2007 17:15:13 -0500 Subject: [PATCH] BUG: Use real path subdirectory check instead of substring comparison to identify when paths are below the relative path tops. Otherwise when the build tree is next to the source tree with the same name plus a suffix the relative path from the binary to source tree is allowed even though it goes outside cmake-managed directories. --- Source/cmLocalGenerator.cxx | 57 +++++++++++-------------------------- 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index dd4d55777..33753c7e5 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2156,6 +2156,13 @@ void cmLocalGenerator::ConfigureRelativePaths() } } +//---------------------------------------------------------------------------- +static bool cmLocalGeneratorNotAbove(const char* a, const char* b) +{ + return (cmSystemTools::ComparePath(a, b) || + cmSystemTools::IsSubDirectory(a, b)); +} + //---------------------------------------------------------------------------- std::string cmLocalGenerator @@ -2181,47 +2188,17 @@ cmLocalGenerator this->RelativePathsConfigured = true; } - std::string original = in_remote; - - // Skip conversion if the path and local are not both in the source or both - // in the binary tree + // Skip conversion if the path and local are not both in the source + // or both in the binary tree. std::string local_path = cmSystemTools::JoinPath(local); - bool should_convert = false; - - // A relative path is safe if both the local and remote locations - // are underneath the current relative path top in the binary tree. - if (local_path.size() >= this->RelativePathTopBinary.size() && - cmSystemTools::ComparePath - (local_path.substr(0, this->RelativePathTopBinary.size()).c_str(), - this->RelativePathTopBinary.c_str())) - { - if (original.size() >= this->RelativePathTopBinary.size() && - cmSystemTools::ComparePath - (original.substr(0, this->RelativePathTopBinary.size()).c_str(), - this->RelativePathTopBinary.c_str())) - { - should_convert = true; - } - } - - // A relative path is safe if both the local and remote locations - // are underneath the current relative path top in the source tree. - if (local_path.size() >= this->RelativePathTopSource.size() && - cmSystemTools::ComparePath - (local_path.substr(0, this->RelativePathTopSource.size()).c_str(), - this->RelativePathTopSource.c_str())) - { - if (original.size() >= this->RelativePathTopSource.size() && - cmSystemTools::ComparePath - (original.substr(0, this->RelativePathTopSource.size()).c_str(), - this->RelativePathTopSource.c_str())) - { - should_convert = true; - } - } - - // Do not convert if it is not safe. - if(!should_convert) + if(!((cmLocalGeneratorNotAbove(local_path.c_str(), + this->RelativePathTopBinary.c_str()) && + cmLocalGeneratorNotAbove(in_remote, + this->RelativePathTopBinary.c_str())) || + (cmLocalGeneratorNotAbove(local_path.c_str(), + this->RelativePathTopSource.c_str()) && + cmLocalGeneratorNotAbove(in_remote, + this->RelativePathTopSource.c_str())))) { return in_remote; }