aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTom Englund <[email protected]>2024-08-07 16:37:09 +0200
committerGitHub <[email protected]>2024-08-07 16:37:09 +0200
commita399f98c68d017152883fbf81d67624ac3254073 (patch)
tree7f9db0a66d1562244c002d91596315cd3795dcf5
parent3e00d7dde774a44b5738d339ce58a4903897942b (diff)
downloadHyprland-a399f98c68d017152883fbf81d67624ac3254073.tar.gz
Hyprland-a399f98c68d017152883fbf81d67624ac3254073.zip
cursormgr: avoid scanning ill formed inherit (#7211)
avoid adding ill formed Inherit lines to inherit vector and later scanning them, it wont change anything in practice but makes the inherit theme parsing more in line with what its supposed todo. also check for return values of the various string functions so we dont end up erasing the wrong thing.
-rw-r--r--src/managers/XCursorManager.cpp51
1 files changed, 42 insertions, 9 deletions
diff --git a/src/managers/XCursorManager.cpp b/src/managers/XCursorManager.cpp
index 76c908db..f2a7ab53 100644
--- a/src/managers/XCursorManager.cpp
+++ b/src/managers/XCursorManager.cpp
@@ -205,23 +205,56 @@ std::unordered_set<std::string> CXCursorManager::themePaths(std::string const& t
Debug::log(LOG, "XCursor parsing index.theme {}", indexTheme);
while (std::getline(infile, line)) {
+ if (line.empty())
+ continue;
+
// Trim leading and trailing whitespace
- line.erase(0, line.find_first_not_of(" \t\n\r"));
- line.erase(line.find_last_not_of(" \t\n\r") + 1);
+ auto pos = line.find_first_not_of(" \t\n\r");
+ if (pos != std::string::npos)
+ line.erase(0, pos);
+
+ pos = line.find_last_not_of(" \t\n\r");
+ if (pos != std::string::npos && pos < line.length()) {
+ line.erase(pos + 1);
+ }
+
+ if (line.rfind("Inherits", 8) != std::string::npos) { // Check if line starts with "Inherits"
+ std::string inheritThemes = line.substr(8); // Extract the part after "Inherits"
+ if (inheritThemes.empty())
+ continue;
- if (line.rfind("Inherits", 0) == 0) { // Check if line starts with "Inherits"
- std::string inheritThemes = line.substr(8); // Extract the part after "Inherits"
// Remove leading whitespace from inheritThemes and =
- inheritThemes.erase(0, inheritThemes.find_first_not_of(" \t\n\r"));
- inheritThemes.erase(0, 1);
- inheritThemes.erase(0, inheritThemes.find_first_not_of(" \t\n\r"));
+ pos = inheritThemes.find_first_not_of(" \t\n\r");
+ if (pos != std::string::npos)
+ inheritThemes.erase(0, pos);
+
+ if (inheritThemes.empty())
+ continue;
+
+ if (inheritThemes.at(0) == '=')
+ inheritThemes.erase(0, 1);
+ else
+ continue; // not correct formatted index.theme
+
+ pos = inheritThemes.find_first_not_of(" \t\n\r");
+ if (pos != std::string::npos)
+ inheritThemes.erase(0, pos);
std::stringstream inheritStream(inheritThemes);
std::string inheritTheme;
while (std::getline(inheritStream, inheritTheme, ',')) {
+ if (inheritTheme.empty())
+ continue;
+
// Trim leading and trailing whitespace from each theme
- inheritTheme.erase(0, inheritTheme.find_first_not_of(" \t\n\r"));
- inheritTheme.erase(inheritTheme.find_last_not_of(" \t\n\r") + 1);
+ pos = inheritTheme.find_first_not_of(" \t\n\r");
+ if (pos != std::string::npos)
+ inheritTheme.erase(0, pos);
+
+ pos = inheritTheme.find_last_not_of(" \t\n\r");
+ if (pos != std::string::npos && pos < inheritTheme.length())
+ inheritTheme.erase(inheritTheme.find_last_not_of(" \t\n\r") + 1);
+
themes.push_back(inheritTheme);
}
}