@@ -666,7 +666,7 @@ int MqttEncode_Connect(byte *tx_buf, int tx_buf_len, MqttConnect *mc_connect)
666
666
{
667
667
int header_len , remain_len ;
668
668
#ifdef WOLFMQTT_V5
669
- word32 props_len = 0 , lwt_props_len = 0 ;
669
+ int props_len = 0 , lwt_props_len = 0 ;
670
670
#endif
671
671
MqttConnectPacket packet = MQTT_CONNECT_INIT ;
672
672
byte * tx_payload ;
@@ -683,11 +683,16 @@ int MqttEncode_Connect(byte *tx_buf, int tx_buf_len, MqttConnect *mc_connect)
683
683
#ifdef WOLFMQTT_V5
684
684
if (mc_connect -> protocol_level >= MQTT_CONNECT_PROTOCOL_LEVEL_5 ) {
685
685
/* Determine length of properties */
686
- remain_len += props_len = MqttEncode_Props (MQTT_PACKET_TYPE_CONNECT ,
686
+ props_len = MqttEncode_Props (MQTT_PACKET_TYPE_CONNECT ,
687
687
mc_connect -> props , NULL );
688
+ if (props_len >= 0 ) {
689
+ remain_len += props_len ;
688
690
689
- /* Determine the length of the "property length" */
690
- remain_len += MqttEncode_Vbi (NULL , props_len );
691
+ /* Determine the length of the "property length" */
692
+ remain_len += MqttEncode_Vbi (NULL , props_len );
693
+ }
694
+ else
695
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_PROPERTY );
691
696
}
692
697
#endif
693
698
@@ -709,11 +714,16 @@ int MqttEncode_Connect(byte *tx_buf, int tx_buf_len, MqttConnect *mc_connect)
709
714
#ifdef WOLFMQTT_V5
710
715
if (mc_connect -> protocol_level >= MQTT_CONNECT_PROTOCOL_LEVEL_5 ) {
711
716
/* Determine length of properties */
712
- remain_len += lwt_props_len = MqttEncode_Props (MQTT_PACKET_TYPE_CONNECT ,
717
+ lwt_props_len = MqttEncode_Props (MQTT_PACKET_TYPE_CONNECT ,
713
718
mc_connect -> lwt_msg -> props , NULL );
719
+ if (lwt_props_len >= 0 ) {
720
+ remain_len += lwt_props_len ;
714
721
715
- /* Determine the length of the "lwt property length" */
716
- remain_len += MqttEncode_Vbi (NULL , lwt_props_len );
722
+ /* Determine the length of the "lwt property length" */
723
+ remain_len += MqttEncode_Vbi (NULL , lwt_props_len );
724
+ }
725
+ else
726
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_PROPERTY );
717
727
}
718
728
#endif
719
729
}
@@ -872,7 +882,7 @@ int MqttEncode_Publish(byte *tx_buf, int tx_buf_len, MqttPublish *publish,
872
882
int header_len , variable_len , payload_len = 0 ;
873
883
byte * tx_payload ;
874
884
#ifdef WOLFMQTT_V5
875
- word32 props_len = 0 ;
885
+ int props_len = 0 ;
876
886
#endif
877
887
878
888
/* Validate required arguments */
@@ -892,11 +902,16 @@ int MqttEncode_Publish(byte *tx_buf, int tx_buf_len, MqttPublish *publish,
892
902
#ifdef WOLFMQTT_V5
893
903
if (publish -> protocol_level >= MQTT_CONNECT_PROTOCOL_LEVEL_5 ) {
894
904
/* Determine length of properties */
895
- variable_len += props_len = MqttEncode_Props (MQTT_PACKET_TYPE_PUBLISH ,
905
+ props_len = MqttEncode_Props (MQTT_PACKET_TYPE_PUBLISH ,
896
906
publish -> props , NULL );
907
+ if (props_len >= 0 ) {
908
+ variable_len += props_len ;
897
909
898
- /* Determine the length of the "property length" */
899
- variable_len += MqttEncode_Vbi (NULL , props_len );
910
+ /* Determine the length of the "property length" */
911
+ variable_len += MqttEncode_Vbi (NULL , props_len );
912
+ }
913
+ else
914
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_PROPERTY );
900
915
}
901
916
#endif
902
917
@@ -1073,7 +1088,7 @@ int MqttEncode_PublishResp(byte* tx_buf, int tx_buf_len, byte type,
1073
1088
byte * tx_payload ;
1074
1089
MqttQoS qos ;
1075
1090
#ifdef WOLFMQTT_V5
1076
- word32 props_len = 0 ;
1091
+ int props_len = 0 ;
1077
1092
#endif
1078
1093
1079
1094
/* Validate required arguments */
@@ -1093,11 +1108,15 @@ int MqttEncode_PublishResp(byte* tx_buf, int tx_buf_len, byte type,
1093
1108
}
1094
1109
if (publish_resp -> props != NULL ) {
1095
1110
/* Determine length of properties */
1096
- remain_len += props_len = MqttEncode_Props ((MqttPacketType )type ,
1111
+ props_len = MqttEncode_Props ((MqttPacketType )type ,
1097
1112
publish_resp -> props , NULL );
1098
-
1099
- /* Determine the length of the "property length" */
1100
- remain_len += MqttEncode_Vbi (NULL , props_len );
1113
+ if (props_len >= 0 ) {
1114
+ remain_len += props_len ;
1115
+ /* Determine the length of the "property length" */
1116
+ remain_len += MqttEncode_Vbi (NULL , props_len );
1117
+ }
1118
+ else
1119
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_PROPERTY );
1101
1120
}
1102
1121
}
1103
1122
#endif
@@ -1225,7 +1244,7 @@ int MqttEncode_Subscribe(byte *tx_buf, int tx_buf_len,
1225
1244
byte * tx_payload ;
1226
1245
MqttTopic * topic ;
1227
1246
#ifdef WOLFMQTT_V5
1228
- word32 props_len = 0 ;
1247
+ int props_len = 0 ;
1229
1248
#endif
1230
1249
1231
1250
/* Validate required arguments */
@@ -1249,11 +1268,16 @@ int MqttEncode_Subscribe(byte *tx_buf, int tx_buf_len,
1249
1268
#ifdef WOLFMQTT_V5
1250
1269
if (subscribe -> protocol_level >= MQTT_CONNECT_PROTOCOL_LEVEL_5 ) {
1251
1270
/* Determine length of properties */
1252
- remain_len += props_len = MqttEncode_Props (MQTT_PACKET_TYPE_SUBSCRIBE ,
1271
+ props_len = MqttEncode_Props (MQTT_PACKET_TYPE_SUBSCRIBE ,
1253
1272
subscribe -> props , NULL );
1273
+ if (props_len >= 0 ) {
1274
+ remain_len += props_len ;
1254
1275
1255
- /* Determine the length of the "property length" */
1256
- remain_len += MqttEncode_Vbi (NULL , props_len );
1276
+ /* Determine the length of the "property length" */
1277
+ remain_len += MqttEncode_Vbi (NULL , props_len );
1278
+ }
1279
+ else
1280
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_PROPERTY );
1257
1281
}
1258
1282
#endif
1259
1283
@@ -1374,7 +1398,7 @@ int MqttEncode_Unsubscribe(byte *tx_buf, int tx_buf_len,
1374
1398
byte * tx_payload ;
1375
1399
MqttTopic * topic ;
1376
1400
#ifdef WOLFMQTT_V5
1377
- word32 props_len = 0 ;
1401
+ int props_len = 0 ;
1378
1402
#endif
1379
1403
1380
1404
/* Validate required arguments */
@@ -1398,11 +1422,15 @@ int MqttEncode_Unsubscribe(byte *tx_buf, int tx_buf_len,
1398
1422
#ifdef WOLFMQTT_V5
1399
1423
if (unsubscribe -> protocol_level >= MQTT_CONNECT_PROTOCOL_LEVEL_5 ) {
1400
1424
/* Determine length of properties */
1401
- remain_len += props_len = MqttEncode_Props (MQTT_PACKET_TYPE_UNSUBSCRIBE ,
1402
- unsubscribe -> props , NULL );
1403
-
1404
- /* Determine the length of the "property length" */
1405
- remain_len += MqttEncode_Vbi (NULL , props_len );
1425
+ props_len = MqttEncode_Props (MQTT_PACKET_TYPE_UNSUBSCRIBE ,
1426
+ unsubscribe -> props , NULL );
1427
+ if (props_len >= 0 ) {
1428
+ remain_len += props_len ;
1429
+ /* Determine the length of the "property length" */
1430
+ remain_len += MqttEncode_Vbi (NULL , props_len );
1431
+ }
1432
+ else
1433
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_PROPERTY );
1406
1434
}
1407
1435
#endif
1408
1436
@@ -1563,7 +1591,7 @@ int MqttEncode_Disconnect(byte *tx_buf, int tx_buf_len,
1563
1591
int header_len ;
1564
1592
int remain_len = 0 ;
1565
1593
#ifdef WOLFMQTT_V5
1566
- word32 props_len = 0 ;
1594
+ int props_len = 0 ;
1567
1595
#endif
1568
1596
1569
1597
/* Validate required arguments */
@@ -1577,12 +1605,15 @@ int MqttEncode_Disconnect(byte *tx_buf, int tx_buf_len,
1577
1605
1578
1606
if (disconnect -> props != NULL ) {
1579
1607
/* Determine length of properties */
1580
- remain_len += props_len = MqttEncode_Props (
1581
- MQTT_PACKET_TYPE_DISCONNECT ,
1608
+ props_len = MqttEncode_Props (MQTT_PACKET_TYPE_DISCONNECT ,
1582
1609
disconnect -> props , NULL );
1583
-
1584
- /* Determine the length of the "property length" */
1585
- remain_len += MqttEncode_Vbi (NULL , props_len );
1610
+ if (props_len >= 0 ) {
1611
+ remain_len += props_len ;
1612
+ /* Determine the length of the "property length" */
1613
+ remain_len += MqttEncode_Vbi (NULL , props_len );
1614
+ }
1615
+ else
1616
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_PROPERTY );
1586
1617
}
1587
1618
if ((remain_len != 0 ) ||
1588
1619
(disconnect -> reason_code != MQTT_REASON_SUCCESS )) {
@@ -1695,7 +1726,7 @@ int MqttEncode_Auth(byte *tx_buf, int tx_buf_len, MqttAuth *auth)
1695
1726
{
1696
1727
int header_len , remain_len = 0 ;
1697
1728
byte * tx_payload ;
1698
- word32 props_len = 0 ;
1729
+ int props_len = 0 ;
1699
1730
1700
1731
/* Validate required arguments */
1701
1732
if ((tx_buf == NULL ) || (tx_buf_len <= 0 ) || (auth == NULL )) {
@@ -1706,11 +1737,15 @@ int MqttEncode_Auth(byte *tx_buf, int tx_buf_len, MqttAuth *auth)
1706
1737
remain_len ++ ;
1707
1738
1708
1739
/* Determine length of properties */
1709
- remain_len += props_len = MqttEncode_Props (MQTT_PACKET_TYPE_AUTH ,
1740
+ props_len = MqttEncode_Props (MQTT_PACKET_TYPE_AUTH ,
1710
1741
auth -> props , NULL );
1711
-
1712
- /* Determine the length of the "property length" */
1713
- remain_len += MqttEncode_Vbi (NULL , props_len );
1742
+ if (props_len >= 0 ) {
1743
+ remain_len += props_len ;
1744
+ /* Determine the length of the "property length" */
1745
+ remain_len += MqttEncode_Vbi (NULL , props_len );
1746
+ }
1747
+ else
1748
+ return MQTT_TRACE_ERROR (MQTT_CODE_ERROR_PROPERTY );
1714
1749
1715
1750
/* Encode fixed header */
1716
1751
header_len = MqttEncode_FixedHeader (tx_buf , tx_buf_len , remain_len ,
0 commit comments