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.

This commit is contained in:
Yumin Yuan 2009-04-15 10:45:29 -04:00
parent aba3d56c92
commit f3035ff78d
1 changed files with 7 additions and 1 deletions

View File

@ -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] == '/' )
{