correct some infinte loop conditions due to bad loop variable sizes; correct missing error handling for zlib during decompression;

pull/121/head
Bryan Biedenkapp 2 months ago
parent c701b8e131
commit 5e2356162c

@ -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);

@ -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);

@ -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;

@ -224,7 +224,7 @@ bool PeerNetwork::writeHAParams(std::vector<HAParameters>& 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;

@ -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;

@ -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];
}

@ -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);

Loading…
Cancel
Save

Powered by TurnKey Linux.