Skip to content
Snippets Groups Projects
Commit c619a692 authored by Yumin Yuan's avatar Yumin Yuan
Browse files

BUG: SystemTools::GetParentDirectory() will crash if "/" is passed in as...

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.
parent 0e3a5ecd
No related branches found
No related tags found
No related merge requests found
......@@ -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] == '/' )
{
......
......@@ -7,4 +7,4 @@ SET(KWSYS_DATE_STAMP_YEAR 2009)
SET(KWSYS_DATE_STAMP_MONTH 04)
# KWSys version date day component. Format is DD.
SET(KWSYS_DATE_STAMP_DAY 14)
SET(KWSYS_DATE_STAMP_DAY 15)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment