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.
This commit is contained in:
Tom Englund 2024-08-07 16:37:09 +02:00 committed by GitHub
parent 3e00d7dde7
commit a399f98c68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)) {
// 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);
if (line.empty())
continue;
// Trim leading and trailing whitespace
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);
}
}