From 6fb8f502050c269597636c3b0bfcf046f7f6a947 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 30 Mar 2024 03:09:22 +0000 Subject: [PATCH] hyprpm: avoid crashes on corrupted headers ref #5329 --- hyprpm/src/core/PluginManager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index c5926c3e..965f2e9d 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -333,7 +333,12 @@ eHeadersErrors CPluginManager::headersValid() { std::string verHeaderContent((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); ifs.close(); - std::string hash = verHeaderContent.substr(verHeaderContent.find("#define GIT_COMMIT_HASH") + 23); + const auto HASHPOS = verHeaderContent.find("#define GIT_COMMIT_HASH"); + + if (HASHPOS == std::string::npos || HASHPOS + 23 >= verHeaderContent.length()) + return HEADERS_CORRUPTED; + + std::string hash = verHeaderContent.substr(HASHPOS + 23); hash = hash.substr(0, hash.find_first_of('\n')); hash = hash.substr(hash.find_first_of('"') + 1); hash = hash.substr(0, hash.find_first_of('"'));