safety check for basename function

This commit is contained in:
Robin Müller 2024-05-24 16:25:18 +02:00
parent 312858eb1c
commit d7124edb5a

View File

@ -178,6 +178,10 @@ ReturnValue_t HostFilesystem::isDirectory(const char *path, bool &isDirectory) {
ReturnValue_t HostFilesystem::getBaseFilename(FilesystemParams params, char *nameBuf, size_t maxLen,
size_t &baseNameLen) {
std::string path(params.path);
size_t lastPos = path.find_last_of("/\\");
if (lastPos == std::string::npos) {
return returnvalue::FAILED;
}
std::string baseName = path.substr(path.find_last_of("/\\") + 1);
if (baseName.size() + 1 > maxLen) {
return returnvalue::FAILED;