serialhdl: Fail early if message exceeds max size

This commit is contained in:
Desuuuu 2022-05-22 18:25:46 +02:00
parent 4d97ca0445
commit 322b3b277b
No known key found for this signature in database
GPG Key ID: 85943F4B2C2CE0DC
1 changed files with 8 additions and 2 deletions

View File

@ -236,15 +236,21 @@ class SerialReader:
self.handlers[name, oid] = callback self.handlers[name, oid] = callback
# Command sending # Command sending
def raw_send(self, cmd, minclock, reqclock, cmd_queue): 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, 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): 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 self.last_notify_id += 1
nid = self.last_notify_id nid = self.last_notify_id
completion = self.reactor.completion() completion = self.reactor.completion()
self.pending_notifications[nid] = completion self.pending_notifications[nid] = completion
self.ffi_lib.serialqueue_send(self.serialqueue, cmd_queue, self.ffi_lib.serialqueue_send(self.serialqueue, cmd_queue,
cmd, len(cmd), minclock, reqclock, nid) cmd, cmdlen, minclock, reqclock, nid)
params = completion.wait() params = completion.wait()
if params is None: if params is None:
self._error("Serial connection closed") self._error("Serial connection closed")