From cf91f51e8e2a38a38c3787f12aadd45a4023d7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 18 Aug 2024 08:31:45 +0200 Subject: [PATCH] Fix CID 1534125; String not null terminated in Path::getCurrentExecutablePath() --- lib/path.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/path.cpp b/lib/path.cpp index f7943980924..8b0b75c8ca0 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -164,7 +164,8 @@ std::string Path::getCurrentExecutablePath(const char* fallback) #else // Linux "/proc/self/exe"; #endif - success = (readlink(procPath, buf, sizeof(buf)) != -1); + // readlink does not null-terminate the string if the buffer is too small, therefore write bufsize - 1 + success = (readlink(procPath, buf, sizeof(buf) - 1) != -1); #endif return success ? std::string(buf) : std::string(fallback); }