Commit eead6f2c authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

utils: File: Fix potential overflow

parent 78779952
......@@ -149,7 +149,7 @@ std::string firstFolder( const std::string& path )
std::string removePath( const std::string& fullPath, const std::string& toRemove )
{
if ( toRemove.length() == 0 )
if ( toRemove.length() == 0 || toRemove.length() > fullPath.length() )
return fullPath;
auto pos = fullPath.find( toRemove );
if ( pos == std::string::npos )
......@@ -245,4 +245,4 @@ bool schemeIs( const std::string& scheme, const std::string& mrl )
}
}
\ No newline at end of file
}
......@@ -94,6 +94,7 @@ TEST( FsUtils, removePath )
ASSERT_EQ( "", utils::file::removePath( "bar/", "bar" ) );
ASSERT_EQ( "", utils::file::removePath( "/f00/", "/f00/" ) );
ASSERT_EQ( "/f00", utils::file::removePath( "/f00", "/path/not/found" ) );
ASSERT_EQ( "/f00", utils::file::removePath( "/f00", "/loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongstring/" ) );
}
TEST( FsUtils, parentFolder )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment