diff options
author | Yumin Yuan <yumin.yuan@kitware.com> | 2009-04-15 14:45:29 (GMT) |
---|---|---|
committer | Yumin Yuan <yumin.yuan@kitware.com> | 2009-04-15 14:45:29 (GMT) |
commit | f3035ff78d77b09eccd9e1f3881663e50ea204e4 (patch) | |
tree | dad70a8075829adcab69b42b1c1f8246f4904cad /Source/kwsys/SystemTools.cxx | |
parent | aba3d56c929256771049ec64a53d2e7067e342b8 (diff) | |
download | CMake-f3035ff78d77b09eccd9e1f3881663e50ea204e4.zip CMake-f3035ff78d77b09eccd9e1f3881663e50ea204e4.tar.gz CMake-f3035ff78d77b09eccd9e1f3881663e50ea204e4.tar.bz2 |
BUG: SystemTools::GetParentDirectory() will crash if "/" is passed in as argement. Valid check is added to make sure the input argment exists, and if "/" is passed in, empty string will be returned.
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 7c81eb0..94b7591 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -3975,12 +3975,18 @@ bool SystemTools::SetPermissions(const char* file, mode_t mode) kwsys_stl::string SystemTools::GetParentDirectory(const char* fileOrDir) { - if ( !fileOrDir || !*fileOrDir ) + if ( !fileOrDir || !*fileOrDir || !SystemTools::FileExists(fileOrDir)) { return ""; } kwsys_stl::string res = fileOrDir; SystemTools::ConvertToUnixSlashes(res); + + // If the root "/" directory is passed in, return empty string + if(strcmp(res.c_str(), "/") ==0 ) + { + return ""; + } kwsys_stl::string::size_type cc = res.size()-1; if ( res[cc] == '/' ) { |