From 3027af55835bb3078b424750ed3601da925ac58b Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 16 Dec 2024 22:42:33 +0000 Subject: [PATCH] Fix int overflow --- lib/packet_mosq.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/packet_mosq.c b/lib/packet_mosq.c index 19a83c292..9ee571aa6 100644 --- a/lib/packet_mosq.c +++ b/lib/packet_mosq.c @@ -504,8 +504,13 @@ static int packet__read_single(struct mosquitto *mosq, enum mosquitto_client_sta len = mosq->in_packet.packet_buffer_to_process; } memcpy(mosq->in_packet.payload, &mosq->in_packet.packet_buffer[mosq->in_packet.packet_buffer_pos], len); - mosq->in_packet.packet_buffer_pos += (uint16_t)len; - mosq->in_packet.packet_buffer_to_process -= (uint16_t)len; + if(len < mosq->in_packet.packet_buffer_to_process){ + mosq->in_packet.packet_buffer_pos += (uint16_t)len; + mosq->in_packet.packet_buffer_to_process -= (uint16_t)len; + }else{ + mosq->in_packet.packet_buffer_pos = 0; + mosq->in_packet.packet_buffer_to_process = 0; + } mosq->in_packet.pos += len; mosq->in_packet.to_process -= len; }