Skip to content

Commit 2a8ef76

Browse files
JanczarKurekJanczar Knurek
andauthored
ipc: Don't crash when given bad input via IPC (#29)
Co-authored-by: Janczar Knurek <[email protected]>
1 parent fdcc9a1 commit 2a8ef76

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/IPCSocket.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,21 @@ bool CIPCSocket::mainThreadParseRequest() {
151151

152152
std::string args = copy.substr(spaceSeparator + 1);
153153
unsigned long long kelvin = g_pHyprsunset->KELVIN;
154-
if (args[0] == '+' || args[0] == '-') {
155-
try {
154+
try {
155+
if (args[0] == '+' || args[0] == '-') {
156156
if (args[0] == '-')
157157
kelvin -= std::stoull(args.substr(1));
158158
else
159159
kelvin += std::stoull(args.substr(1));
160-
} catch (std::exception& e) {
161-
m_szReply = "Invalid temperature (should be in range 1000-20000)";
162-
return false;
163-
}
164-
165-
kelvin = std::clamp(kelvin, 1000ull, 20000ull);
166-
} else
167-
kelvin = std::stoull(args);
168-
160+
kelvin = std::clamp(kelvin, 1000ull, 20000ull);
161+
} else
162+
kelvin = std::stoull(args);
163+
} catch (std::exception& e) {
164+
m_szReply = "Invalid temperature (should be an integer in range 1000-20000)";
165+
return false;
166+
}
169167
if (kelvin < 1000 || kelvin > 20000) {
170-
m_szReply = "Invalid temperature (should be in range 1000-20000)";
168+
m_szReply = "Invalid temperature (should be an integer in range 1000-20000)";
171169
return false;
172170
}
173171

0 commit comments

Comments
 (0)