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:
parent
aba3d56c92
commit
f3035ff78d
|
@ -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] == '/' )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue