ipc: Don't crash when given bad input via IPC (#29)
Some checks failed
Build / nix (push) Has been cancelled

Co-authored-by: Janczar Knurek <jacek@beit.tech>
This commit is contained in:
JanczarKurek 2025-05-05 23:43:37 +02:00 committed by GitHub
parent fdcc9a1e17
commit 2a8ef76c6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -151,23 +151,21 @@ bool CIPCSocket::mainThreadParseRequest() {
std::string args = copy.substr(spaceSeparator + 1);
unsigned long long kelvin = g_pHyprsunset->KELVIN;
if (args[0] == '+' || args[0] == '-') {
try {
try {
if (args[0] == '+' || args[0] == '-') {
if (args[0] == '-')
kelvin -= std::stoull(args.substr(1));
else
kelvin += std::stoull(args.substr(1));
} catch (std::exception& e) {
m_szReply = "Invalid temperature (should be in range 1000-20000)";
return false;
}
kelvin = std::clamp(kelvin, 1000ull, 20000ull);
} else
kelvin = std::stoull(args);
kelvin = std::clamp(kelvin, 1000ull, 20000ull);
} else
kelvin = std::stoull(args);
} catch (std::exception& e) {
m_szReply = "Invalid temperature (should be an integer in range 1000-20000)";
return false;
}
if (kelvin < 1000 || kelvin > 20000) {
m_szReply = "Invalid temperature (should be in range 1000-20000)";
m_szReply = "Invalid temperature (should be an integer in range 1000-20000)";
return false;
}