From 5e2356162c250be94369281a05154a3c7b59c632 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Thu, 10 Sep 2026 11:29:58 -0400 Subject: [PATCH] correct some infinte loop conditions due to bad loop variable sizes; correct missing error handling for zlib during decompression; --- src/common/network/PacketBuffer.cpp | 2 +- src/common/network/packet/Master.cpp | 4 ++-- src/common/zlib/Compression.cpp | 4 ++-- src/fne/network/PeerNetwork.cpp | 2 +- src/fne/network/TrafficNetwork.cpp | 2 +- src/fne/network/callhandler/packetdata/DMRPacketData.cpp | 2 +- src/fne/network/packet/Replication.cpp | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/common/network/PacketBuffer.cpp b/src/common/network/PacketBuffer.cpp index 52b44317..fff9f8e2 100644 --- a/src/common/network/PacketBuffer.cpp +++ b/src/common/network/PacketBuffer.cpp @@ -140,7 +140,7 @@ bool PacketBuffer::decode(const uint8_t* data, uint8_t** message, uint32_t* outL uint32_t copyLen = (compressedLen > FRAG_BLOCK_SIZE) ? FRAG_BLOCK_SIZE : compressedLen; ::memcpy(buffer, firstFrag->data, copyLen); } else { - for (uint8_t i = 0U; i <= blockCnt; i++) { + for (uint16_t i = 0U; i <= blockCnt; i++) { auto it = fragments.find(i); if (it == fragments.end() || it->second == nullptr || it->second->data == nullptr) { LogError(LOG_NET, "%s, Packet Fragment, error missing block %u, packet dropped", m_name, i); diff --git a/src/common/network/packet/Master.cpp b/src/common/network/packet/Master.cpp index 016736c2..9b424000 100644 --- a/src/common/network/packet/Master.cpp +++ b/src/common/network/packet/Master.cpp @@ -201,8 +201,8 @@ bool Network::PacketHandler::master(Network* network, uint32_t peerId, uint32_t len /= HA_PARAMS_ENTRY_LEN; } - uint8_t offs = 10U; - for (uint8_t i = 0U; i < len; i++, offs += HA_PARAMS_ENTRY_LEN) { + uint32_t offs = 10U; + for (uint32_t i = 0U; i < len; i++, offs += HA_PARAMS_ENTRY_LEN) { uint32_t ipAddr = GET_UINT32(buffer, offs + 4U); uint16_t port = GET_UINT16(buffer, offs + 8U); diff --git a/src/common/zlib/Compression.cpp b/src/common/zlib/Compression.cpp index d3cf80d3..60cad122 100644 --- a/src/common/zlib/Compression.cpp +++ b/src/common/zlib/Compression.cpp @@ -144,8 +144,8 @@ UInt8Array Compression::decompress(const uint8_t* buffer, uint32_t len, uint32_t strm.next_out = outbuffer; ret = inflate(&strm, Z_NO_FLUSH); - if (ret == Z_STREAM_ERROR) { - LogError(LOG_HOST, "ZLIB error decompressing compressed data; stream error"); + if (ret == Z_STREAM_ERROR || ret == Z_DATA_ERROR || ret == Z_BUF_ERROR) { + LogError(LOG_HOST, "ZLIB error decompressing compressed data; stream/data error"); inflateEnd(&strm); delete[] data; return nullptr; diff --git a/src/fne/network/PeerNetwork.cpp b/src/fne/network/PeerNetwork.cpp index 6a1159e7..4d8b6d98 100644 --- a/src/fne/network/PeerNetwork.cpp +++ b/src/fne/network/PeerNetwork.cpp @@ -224,7 +224,7 @@ bool PeerNetwork::writeHAParams(std::vector& haParams) SET_UINT32((len - 4U), buffer, 0U); uint32_t offs = 4U; - for (uint8_t i = 0U; i < haParams.size(); i++) { + for (uint32_t i = 0U; i < haParams.size(); i++) { uint32_t peerId = haParams[i].peerId; uint32_t ipAddr = haParams[i].masterIP; uint16_t port = haParams[i].masterPort; diff --git a/src/fne/network/TrafficNetwork.cpp b/src/fne/network/TrafficNetwork.cpp index 335072e4..dddcd9d8 100644 --- a/src/fne/network/TrafficNetwork.cpp +++ b/src/fne/network/TrafficNetwork.cpp @@ -2412,7 +2412,7 @@ void TrafficNetwork::writeHAParameters(uint32_t peerId, uint32_t streamId, bool uint32_t offs = 4U; m_peerReplicaHAParams.lock(false); - for (uint8_t i = 0U; i < m_peerReplicaHAParams.size(); i++) { + for (uint32_t i = 0U; i < m_peerReplicaHAParams.size(); i++) { uint32_t peerId = m_peerReplicaHAParams[i].peerId; uint32_t ipAddr = m_peerReplicaHAParams[i].masterIP; uint16_t port = m_peerReplicaHAParams[i].masterPort; diff --git a/src/fne/network/callhandler/packetdata/DMRPacketData.cpp b/src/fne/network/callhandler/packetdata/DMRPacketData.cpp index d48669d8..bfba7840 100644 --- a/src/fne/network/callhandler/packetdata/DMRPacketData.cpp +++ b/src/fne/network/callhandler/packetdata/DMRPacketData.cpp @@ -529,7 +529,7 @@ void DMRPacketData::dispatch(uint32_t peerId, dmr::data::NetData& dmrData, const // ooookay -- lets do the insane, and ridiculously stupid, ETSI Big-Endian reversed byte ordering bullshit for the CRC-32 uint8_t crcBytes[MAX_PDU_COUNT * DMR_PDU_UNCODED_LENGTH_BYTES + 2U]; ::memset(crcBytes, 0x00U, MAX_PDU_COUNT * DMR_PDU_UNCODED_LENGTH_BYTES + 2U); - for (uint8_t i = 0U; i < status->pduDataOffset - 4U; i += 2U) { + for (uint32_t i = 0U; i < status->pduDataOffset - 4U; i += 2U) { crcBytes[i + 1U] = status->pduUserData[i]; crcBytes[i] = status->pduUserData[i + 1U]; } diff --git a/src/fne/network/packet/Replication.cpp b/src/fne/network/packet/Replication.cpp index 33691d36..80f7558e 100644 --- a/src/fne/network/packet/Replication.cpp +++ b/src/fne/network/packet/Replication.cpp @@ -150,8 +150,8 @@ void MetadataNetwork::PacketHandler::replication(TrafficNetwork* network, Metada len /= HA_PARAMS_ENTRY_LEN; } - uint8_t offs = 4U; - for (uint8_t i = 0U; i < len; i++, offs += HA_PARAMS_ENTRY_LEN) { + uint32_t offs = 4U; + for (uint32_t i = 0U; i < len; i++, offs += HA_PARAMS_ENTRY_LEN) { uint32_t peerId = GET_UINT32(rawPayload, offs); uint32_t ipAddr = GET_UINT32(rawPayload, offs + 4U); uint16_t port = GET_UINT16(rawPayload, offs + 8U);