Prevent information about file existence outside the allowed paths to leak by mimicing boost::filesystem::weakly_canonical.

This commit is contained in:
Daniel Kirchner
2018-04-11 18:52:22 +02:00
parent f39f36f2c7
commit c15cb6cc7a
4 changed files with 33 additions and 7 deletions
+20
View File
@@ -167,3 +167,23 @@ int dev::readStandardInputChar()
DisableConsoleBuffering disableConsoleBuffering;
return cin.get();
}
boost::filesystem::path dev::weaklyCanonicalFilesystemPath(boost::filesystem::path const &_path)
{
if (boost::filesystem::exists(_path))
return boost::filesystem::canonical(_path);
else
{
boost::filesystem::path head(_path);
boost::filesystem::path tail;
for (auto it = --_path.end(); !head.empty(); --it)
{
if (boost::filesystem::exists(head))
break;
tail = (*it) / tail;
head.remove_filename();
}
head = boost::filesystem::canonical(head);
return head / tail;
}
}