From 535c628cd06964c6f4e8841f4681656f7f2471ba Mon Sep 17 00:00:00 2001 From: Midgard Date: Mon, 7 Sep 2020 19:05:54 +0200 Subject: [PATCH] Add more payload length checks --- lib/obus_can.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/obus_can.cpp b/lib/obus_can.cpp index d242019..0deb09a 100644 --- a/lib/obus_can.cpp +++ b/lib/obus_can.cpp @@ -124,6 +124,10 @@ bool receive(struct message *msg) { break; case OBUS_PAYLDTYPE_COUNT: + if (receive_frame.can_dlc < 2) { + Serial.println(F("W Received illegal count msg: payload <2")); + return false; + } msg->count = receive_frame.data[1]; break; @@ -156,7 +160,8 @@ void send(struct message *msg) { uint8_t length = 1; send_frame.data[0] = msg->msg_type; - switch (payload_type(msg->from.type, msg->msg_type)) { + uint8_t pyld_type = payload_type(msg->from.type, msg->msg_type); + switch (pyld_type) { case OBUS_PAYLDTYPE_EMPTY: break; @@ -176,7 +181,8 @@ void send(struct message *msg) { break; default: - Serial.println(F("Unknown payload type")); + Serial.print(F("E Unknown payload type ")); + Serial.println(pyld_type); return; }