Skip to content

Commit

Permalink
config: fix a possible crash in the monitor config parser (#9460)
Browse files Browse the repository at this point in the history
* Less crash-prone monitor config parser

* clang-format
  • Loading branch information
cyanbun96 authored Feb 23, 2025
1 parent 2e81648 commit e594646
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,11 +1946,16 @@ std::optional<std::string> CConfigManager::handleMonitor(const std::string& comm
error += "invalid resolution ";
newrule.resolution = Vector2D();
} else {
newrule.resolution.x = stoi(ARGS[1].substr(0, ARGS[1].find_first_of('x')));
newrule.resolution.y = stoi(ARGS[1].substr(ARGS[1].find_first_of('x') + 1, ARGS[1].find_first_of('@')));
try {
newrule.resolution.x = stoi(ARGS[1].substr(0, ARGS[1].find_first_of('x')));
newrule.resolution.y = stoi(ARGS[1].substr(ARGS[1].find_first_of('x') + 1, ARGS[1].find_first_of('@')));

if (ARGS[1].contains("@"))
newrule.refreshRate = stof(ARGS[1].substr(ARGS[1].find_first_of('@') + 1));
if (ARGS[1].contains("@"))
newrule.refreshRate = stof(ARGS[1].substr(ARGS[1].find_first_of('@') + 1));
} catch (...) {
error += "invalid resolution ";
newrule.resolution = Vector2D();
}
}
}

Expand Down

0 comments on commit e594646

Please sign in to comment.