From 205b5593a8e6865b8b0ffe81b1e8feebe85340eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Fri, 12 May 2023 21:05:36 +0200 Subject: [PATCH] Print warning if decode of zero length telegram is attempted. --- src/wmbus.cc | 2 ++ src/wmbus_rawtty.cc | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/wmbus.cc b/src/wmbus.cc index 54e2dad..8057e65 100644 --- a/src/wmbus.cc +++ b/src/wmbus.cc @@ -4126,6 +4126,8 @@ bool BusDeviceCommonImplementation::handleTelegram(AboutTelegram &about, vector< bool handled = false; last_received_ = time(NULL); + assert(frame.size() > 0); + if (about.type == FrameType::MBUS && frame.size() == 1) { if (frame[0] == 0xe5) diff --git a/src/wmbus_rawtty.cc b/src/wmbus_rawtty.cc index 8bcd559..a8535a6 100644 --- a/src/wmbus_rawtty.cc +++ b/src/wmbus_rawtty.cc @@ -211,6 +211,14 @@ void WMBusRawTTY::processSerialData() { FrameStatus status = checkWMBusFrame(data_buffer_, &frame_length, &payload_len, &payload_offset, false); + if (payload_len == 0) + { + verbose("(rawtty) protocol error in message received length byte is zero!\n"); + string msg = bin2hex(data_buffer_); + debug("(rawtty) protocol error \"%s\"\n", msg.c_str()); + data_buffer_.clear(); + break; + } if (status == PartialFrame) { // Partial frame, stop eating.