From d7124edb5a8c406c28c6124593a5088f4709f895 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 24 May 2024 16:25:18 +0200 Subject: [PATCH] safety check for basename function --- src/fsfw_hal/host/HostFilesystem.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/fsfw_hal/host/HostFilesystem.cpp b/src/fsfw_hal/host/HostFilesystem.cpp index f8739fb8..026910a6 100644 --- a/src/fsfw_hal/host/HostFilesystem.cpp +++ b/src/fsfw_hal/host/HostFilesystem.cpp @@ -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;