@@ -500,6 +500,10 @@ int MqttDecode_Props(MqttPacketType packet, MqttProp** props, byte* pbuf,
500
500
}
501
501
502
502
/* Decode the Identifier */
503
+ if (buf_len < (word32 )(buf - pbuf )) {
504
+ rc = MQTT_TRACE_ERROR (MQTT_CODE_ERROR_OUT_OF_BUFFER );
505
+ break ;
506
+ }
503
507
rc = MqttDecode_Vbi (buf , (word32 * )& cur_prop -> type ,
504
508
(word32 )(buf_len - (buf - pbuf )));
505
509
if (rc < 0 ) {
@@ -562,6 +566,10 @@ int MqttDecode_Props(MqttPacketType packet, MqttProp** props, byte* pbuf,
562
566
}
563
567
case MQTT_DATA_TYPE_VAR_INT :
564
568
{
569
+ if (buf_len < (word32 )(buf - pbuf )) {
570
+ rc = MQTT_TRACE_ERROR (MQTT_CODE_ERROR_OUT_OF_BUFFER );
571
+ break ;
572
+ }
565
573
tmp = MqttDecode_Vbi (buf , & cur_prop -> data_int ,
566
574
(word32 )(buf_len - (buf - pbuf )));
567
575
if (tmp < 0 ) {
@@ -829,6 +837,9 @@ int MqttDecode_ConnectAck(byte *rx_buf, int rx_buf_len,
829
837
word32 props_len = 0 ;
830
838
int tmp ;
831
839
/* Decode Length of Properties */
840
+ if (rx_buf_len < (rx_payload - rx_buf )) {
841
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_OUT_OF_BUFFER );
842
+ }
832
843
tmp = MqttDecode_Vbi (rx_payload , & props_len ,
833
844
(word32 )(rx_buf_len - (rx_payload - rx_buf )));
834
845
if (tmp < 0 ) {
@@ -1011,6 +1022,9 @@ int MqttDecode_Publish(byte *rx_buf, int rx_buf_len, MqttPublish *publish)
1011
1022
int tmp ;
1012
1023
1013
1024
/* Decode Length of Properties */
1025
+ if (rx_buf_len < (rx_payload - rx_buf )) {
1026
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_OUT_OF_BUFFER );
1027
+ }
1014
1028
tmp = MqttDecode_Vbi (rx_payload , & props_len ,
1015
1029
(word32 )(rx_buf_len - (rx_payload - rx_buf )));
1016
1030
if (tmp < 0 )
@@ -1169,6 +1183,9 @@ int MqttDecode_PublishResp(byte* rx_buf, int rx_buf_len, byte type,
1169
1183
int tmp ;
1170
1184
1171
1185
/* Decode Length of Properties */
1186
+ if (rx_buf_len < (rx_payload - rx_buf )) {
1187
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_OUT_OF_BUFFER );
1188
+ }
1172
1189
tmp = MqttDecode_Vbi (rx_payload , & props_len ,
1173
1190
(word32 )(rx_buf_len - (rx_payload - rx_buf )));
1174
1191
if (tmp < 0 )
@@ -1313,6 +1330,9 @@ int MqttDecode_SubscribeAck(byte* rx_buf, int rx_buf_len,
1313
1330
int tmp ;
1314
1331
1315
1332
/* Decode Length of Properties */
1333
+ if (rx_buf_len < (rx_payload - rx_buf )) {
1334
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_OUT_OF_BUFFER );
1335
+ }
1316
1336
tmp = MqttDecode_Vbi (rx_payload , & props_len ,
1317
1337
(word32 )(rx_buf_len - (rx_payload - rx_buf )));
1318
1338
if (tmp < 0 )
@@ -1452,6 +1472,9 @@ int MqttDecode_UnsubscribeAck(byte *rx_buf, int rx_buf_len,
1452
1472
int tmp ;
1453
1473
1454
1474
/* Decode Length of Properties */
1475
+ if (rx_buf_len < (rx_payload - rx_buf )) {
1476
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_OUT_OF_BUFFER );
1477
+ }
1455
1478
tmp = MqttDecode_Vbi (rx_payload , & props_len ,
1456
1479
(word32 )(rx_buf_len - (rx_payload - rx_buf )));
1457
1480
if (tmp < 0 )
@@ -1635,6 +1658,9 @@ int MqttDecode_Disconnect(byte *rx_buf, int rx_buf_len, MqttDisconnect *disc)
1635
1658
1636
1659
if (remain_len > 1 ) {
1637
1660
/* Decode Length of Properties */
1661
+ if (rx_buf_len < (rx_payload - rx_buf )) {
1662
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_OUT_OF_BUFFER );
1663
+ }
1638
1664
tmp = MqttDecode_Vbi (rx_payload , & props_len ,
1639
1665
(word32 )(rx_buf_len - (rx_payload - rx_buf )));
1640
1666
if (tmp < 0 )
@@ -1750,6 +1776,9 @@ int MqttDecode_Auth(byte *rx_buf, int rx_buf_len, MqttAuth *auth)
1750
1776
auth -> props = NULL ;
1751
1777
1752
1778
/* Decode Length of Properties */
1779
+ if (rx_buf_len < (rx_payload - rx_buf )) {
1780
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_OUT_OF_BUFFER );
1781
+ }
1753
1782
tmp = MqttDecode_Vbi (rx_payload , & props_len ,
1754
1783
(word32 )(rx_buf_len - (rx_payload - rx_buf )));
1755
1784
if (tmp < 0 )
@@ -2018,6 +2047,9 @@ int MqttPacket_Read(MqttClient *client, byte* rx_buf, int rx_buf_len,
2018
2047
}
2019
2048
2020
2049
/* Try and decode remaining length */
2050
+ if (rx_buf_len < (client -> packet .header_len - (i + 1 ))) {
2051
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_OUT_OF_BUFFER );
2052
+ }
2021
2053
rc = MqttDecode_Vbi (header -> len ,
2022
2054
(word32 * )& client -> packet .remain_len ,
2023
2055
rx_buf_len - (client -> packet .header_len - (i + 1 )));
0 commit comments