fix possible crash caused by malformed rate request
This commit is contained in:
+3
-3
@@ -118,7 +118,7 @@ if (schemes.interrupt.enabled) {
|
|||||||
const parsed = message.toString().split(" ");
|
const parsed = message.toString().split(" ");
|
||||||
const cmd = parsed[0];
|
const cmd = parsed[0];
|
||||||
// command is rate and the value is valid
|
// command is rate and the value is valid
|
||||||
if (cmd === "rate" && parsed[1] >= schemes.interrupt["min-rate"] && parsed[1] <= schemes.interrupt["max-rate"]) {
|
if (cmd === "rate" && parsed.length === 2 && parsed[1] >= schemes.interrupt["min-rate"] && parsed[1] <= schemes.interrupt["max-rate"]) {
|
||||||
// get requested rate in ms
|
// get requested rate in ms
|
||||||
const rate = Number(parsed[1]) * 1000;
|
const rate = Number(parsed[1]) * 1000;
|
||||||
// if timer has not started, start it with requested rate
|
// if timer has not started, start it with requested rate
|
||||||
@@ -142,12 +142,12 @@ if (schemes.interrupt.enabled) {
|
|||||||
}
|
}
|
||||||
// command is rate but the requested value is out of bounds, terminate socket
|
// command is rate but the requested value is out of bounds, terminate socket
|
||||||
else if (cmd === "rate") {
|
else if (cmd === "rate") {
|
||||||
socket.send(`error: rate must be in range [${schemes.interrupt["min-rate"]}, ${schemes.interrupt["max-rate"]}].`);
|
socket.send(`error: rate <rate> must be in range [${schemes.interrupt["min-rate"]}, ${schemes.interrupt["max-rate"]}].`);
|
||||||
socket.terminate();
|
socket.terminate();
|
||||||
}
|
}
|
||||||
// otherwise, command is invalid, terminate socket
|
// otherwise, command is invalid, terminate socket
|
||||||
else {
|
else {
|
||||||
socket.send(`error: ${cmd} command not found.`);
|
socket.send(`error: ${cmd} command not supported.`);
|
||||||
socket.terminate();
|
socket.terminate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user