From 486508e4ff7428203450d8d27c989c3ff3599fea Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Mon, 6 Jul 2026 18:16:03 +0000 Subject: [PATCH] fix possible crash caused by malformed rate request --- src/routes/sync.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/routes/sync.js b/src/routes/sync.js index 9c6fdf1..665a827 100644 --- a/src/routes/sync.js +++ b/src/routes/sync.js @@ -118,7 +118,7 @@ if (schemes.interrupt.enabled) { const parsed = message.toString().split(" "); const cmd = parsed[0]; // 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 const rate = Number(parsed[1]) * 1000; // 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 else if (cmd === "rate") { - socket.send(`error: rate must be in range [${schemes.interrupt["min-rate"]}, ${schemes.interrupt["max-rate"]}].`); + socket.send(`error: rate must be in range [${schemes.interrupt["min-rate"]}, ${schemes.interrupt["max-rate"]}].`); socket.terminate(); } // otherwise, command is invalid, terminate socket else { - socket.send(`error: ${cmd} command not found.`); + socket.send(`error: ${cmd} command not supported.`); socket.terminate(); } });