From 322b3b277b43df1b5944bbec2eb2e0c5b0c22b3c Mon Sep 17 00:00:00 2001 From: Desuuuu Date: Sun, 22 May 2022 18:25:46 +0200 Subject: [PATCH] serialhdl: Fail early if message exceeds max size --- klippy/serialhdl.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/klippy/serialhdl.py b/klippy/serialhdl.py index b916ab20..02c5c341 100644 --- a/klippy/serialhdl.py +++ b/klippy/serialhdl.py @@ -236,15 +236,21 @@ class SerialReader: self.handlers[name, oid] = callback # Command sending def raw_send(self, cmd, minclock, reqclock, cmd_queue): + cmdlen = len(cmd) + if cmdlen > msgproto.MESSAGE_PAYLOAD_MAX: + self._error("Message is too long (%d bytes)" % (cmdlen,)) self.ffi_lib.serialqueue_send(self.serialqueue, cmd_queue, - cmd, len(cmd), minclock, reqclock, 0) + cmd, cmdlen, minclock, reqclock, 0) def raw_send_wait_ack(self, cmd, minclock, reqclock, cmd_queue): + cmdlen = len(cmd) + if cmdlen > msgproto.MESSAGE_PAYLOAD_MAX: + self._error("Message is too long (%d bytes)" % (cmdlen,)) self.last_notify_id += 1 nid = self.last_notify_id completion = self.reactor.completion() self.pending_notifications[nid] = completion self.ffi_lib.serialqueue_send(self.serialqueue, cmd_queue, - cmd, len(cmd), minclock, reqclock, nid) + cmd, cmdlen, minclock, reqclock, nid) params = completion.wait() if params is None: self._error("Serial connection closed")