Skip to content

Commit

Permalink
xcursormgr: avoid scanning ill formed inherit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gulafaran committed Aug 7, 2024
1 parent f36c625 commit 2d05585
Showing 1 changed file with 42 additions and 9 deletions.
51 changes: 42 additions & 9 deletions src/managers/XCursorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 2d05585

Please sign in to comment.