[cmake-commits] king committed cmLocalGenerator.cxx 1.199 1.200

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Mar 9 17:15:15 EST 2007


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv10365

Modified Files:
	cmLocalGenerator.cxx 
Log Message:
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.


Index: cmLocalGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalGenerator.cxx,v
retrieving revision 1.199
retrieving revision 1.200
diff -u -d -r1.199 -r1.200
--- cmLocalGenerator.cxx	9 Mar 2007 15:30:07 -0000	1.199
+++ cmLocalGenerator.cxx	9 Mar 2007 22:15:13 -0000	1.200
@@ -2157,6 +2157,13 @@
 }
 
 //----------------------------------------------------------------------------
+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 @@
     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;
     }



More information about the Cmake-commits mailing list