Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/mqttnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ static int NetRead(void *context, byte* buf, int buf_len,
}
else {
rc = bytes;
/* Clamp to requested length so the return value cannot overflow */
if (rc > buf_len) {
rc = buf_len;
}
}
Comment on lines 174 to 180

return rc;
Expand Down Expand Up @@ -1851,6 +1855,10 @@ static int NetRead_ex(void *context, byte* buf, int buf_len,
}
else {
rc = bytes;
/* Clamp to requested length so the return value cannot overflow */
if (rc > buf_len) {
rc = buf_len;
}
}

return rc;
Expand Down
5 changes: 5 additions & 0 deletions src/mqtt_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -4042,6 +4042,11 @@ int MqttPacket_Read(MqttClient *client, byte* rx_buf, int rx_buf_len,
if (rc <= 0) {
return MqttPacket_HandleNetError(client, rc);
}
/* Socket read must not return more than requested */
if (rc > remain_read) {
return MqttPacket_HandleNetError(client,
MQTT_TRACE_ERROR(MQTT_CODE_ERROR_NETWORK));
}
remain_read = rc;
}
break;
Expand Down
4 changes: 4 additions & 0 deletions src/mqtt_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ int MqttSocket_Read(MqttClient *client, byte* buf, int buf_len, int timeout_ms)
/* return length read and reset position */
rc = client->read.pos;
client->read.pos = 0;
/* Clamp to requested length so the return value cannot overflow */
if (rc > buf_len) {
rc = buf_len;
}
}

return rc;
Expand Down
Loading