From 41044d22714faf54c7d5163d2732f736c93d56ed Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Sat, 13 Apr 2024 00:29:42 -0400 Subject: [PATCH] fix a potential situation where we may get a length stuck on the queue (this shouldn't happen but, this is protection logic to ensure it never happens); --- src/host/modem/Modem.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/host/modem/Modem.cpp b/src/host/modem/Modem.cpp index 4a163674..a24830c9 100644 --- a/src/host/modem/Modem.cpp +++ b/src/host/modem/Modem.cpp @@ -1044,6 +1044,13 @@ uint32_t Modem::readP25Frame(uint8_t* data) uint16_t len = 0U; len = (length[0U] << 8) + length[1U]; + + // this ensures we never get in a situation where we have length stuck on the queue + if (m_rxP25Queue.dataSize() == 2U && len > m_rxP25Queue.dataSize()) { + m_rxP25Queue.get(length, 2U); // ensure we pop the length off + return 0U; + } + if (m_rxP25Queue.dataSize() >= len) { m_rxP25Queue.get(length, 2U); // ensure we pop the length off m_rxP25Queue.get(data, len);