diff options
author | Brad King <brad.king@kitware.com> | 2007-03-09 22:15:13 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2007-03-09 22:15:13 (GMT) |
commit | 1e25f2b3db126f92e4fd7f59d95205c006df6844 (patch) | |
tree | 2fc3443586716953708e30e2542e3d222cd7e119 /Source/cmLocalGenerator.cxx | |
parent | 0e8d822b180c73129017073815e6205c990cadf7 (diff) | |
download | CMake-1e25f2b3db126f92e4fd7f59d95205c006df6844.zip CMake-1e25f2b3db126f92e4fd7f59d95205c006df6844.tar.gz CMake-1e25f2b3db126f92e4fd7f59d95205c006df6844.tar.bz2 |
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.
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r-- | Source/cmLocalGenerator.cxx | 57 |
1 files changed, 17 insertions, 40 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index dd4d557..33753c7 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2157,6 +2157,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 ::ConvertToRelativePath(const std::vector<std::string>& local, @@ -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; } |