hyprpm: avoid crashes on corrupted headers

ref #5329
This commit is contained in:
Vaxry 2024-03-30 03:09:22 +00:00
parent 54376d7b5f
commit 6fb8f50205
1 changed files with 6 additions and 1 deletions

View File

@ -333,7 +333,12 @@ eHeadersErrors CPluginManager::headersValid() {
std::string verHeaderContent((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
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('"'));