From f3035ff78d77b09eccd9e1f3881663e50ea204e4 Mon Sep 17 00:00:00 2001 From: Yumin Yuan Date: Wed, 15 Apr 2009 10:45:29 -0400 Subject: [PATCH] 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. --- Source/kwsys/SystemTools.cxx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 7c81eb08f..94b75915b 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] == '/' ) {