Skip to content

Commit

Permalink
Fix int overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Dec 16, 2024
1 parent e09213c commit 3027af5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/packet_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 3027af5

Please sign in to comment.