@@ -666,7 +666,7 @@ int MqttEncode_Connect(byte *tx_buf, int tx_buf_len, MqttConnect *mc_connect)
666666{
667667 int header_len , remain_len ;
668668#ifdef WOLFMQTT_V5
669- word32 props_len = 0 , lwt_props_len = 0 ;
669+ int props_len = 0 , lwt_props_len = 0 ;
670670#endif
671671 MqttConnectPacket packet = MQTT_CONNECT_INIT ;
672672 byte * tx_payload ;
@@ -683,11 +683,16 @@ int MqttEncode_Connect(byte *tx_buf, int tx_buf_len, MqttConnect *mc_connect)
683683#ifdef WOLFMQTT_V5
684684 if (mc_connect -> protocol_level >= MQTT_CONNECT_PROTOCOL_LEVEL_5 ) {
685685 /* Determine length of properties */
686- remain_len += props_len = MqttEncode_Props (MQTT_PACKET_TYPE_CONNECT ,
686+ props_len = MqttEncode_Props (MQTT_PACKET_TYPE_CONNECT ,
687687 mc_connect -> props , NULL );
688+ if (props_len >= 0 ) {
689+ remain_len += props_len ;
688690
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 );
691696 }
692697#endif
693698
@@ -709,11 +714,16 @@ int MqttEncode_Connect(byte *tx_buf, int tx_buf_len, MqttConnect *mc_connect)
709714#ifdef WOLFMQTT_V5
710715 if (mc_connect -> protocol_level >= MQTT_CONNECT_PROTOCOL_LEVEL_5 ) {
711716 /* 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 ,
713718 mc_connect -> lwt_msg -> props , NULL );
719+ if (lwt_props_len >= 0 ) {
720+ remain_len += lwt_props_len ;
714721
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 );
717727 }
718728#endif
719729 }
@@ -872,7 +882,7 @@ int MqttEncode_Publish(byte *tx_buf, int tx_buf_len, MqttPublish *publish,
872882 int header_len , variable_len , payload_len = 0 ;
873883 byte * tx_payload ;
874884#ifdef WOLFMQTT_V5
875- word32 props_len = 0 ;
885+ int props_len = 0 ;
876886#endif
877887
878888 /* Validate required arguments */
@@ -892,11 +902,16 @@ int MqttEncode_Publish(byte *tx_buf, int tx_buf_len, MqttPublish *publish,
892902#ifdef WOLFMQTT_V5
893903 if (publish -> protocol_level >= MQTT_CONNECT_PROTOCOL_LEVEL_5 ) {
894904 /* Determine length of properties */
895- variable_len += props_len = MqttEncode_Props (MQTT_PACKET_TYPE_PUBLISH ,
905+ props_len = MqttEncode_Props (MQTT_PACKET_TYPE_PUBLISH ,
896906 publish -> props , NULL );
907+ if (props_len >= 0 ) {
908+ variable_len += props_len ;
897909
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 );
900915 }
901916#endif
902917
@@ -1073,7 +1088,7 @@ int MqttEncode_PublishResp(byte* tx_buf, int tx_buf_len, byte type,
10731088 byte * tx_payload ;
10741089 MqttQoS qos ;
10751090#ifdef WOLFMQTT_V5
1076- word32 props_len = 0 ;
1091+ int props_len = 0 ;
10771092#endif
10781093
10791094 /* Validate required arguments */
@@ -1093,11 +1108,15 @@ int MqttEncode_PublishResp(byte* tx_buf, int tx_buf_len, byte type,
10931108 }
10941109 if (publish_resp -> props != NULL ) {
10951110 /* Determine length of properties */
1096- remain_len += props_len = MqttEncode_Props ((MqttPacketType )type ,
1111+ props_len = MqttEncode_Props ((MqttPacketType )type ,
10971112 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 );
11011120 }
11021121 }
11031122#endif
@@ -1225,7 +1244,7 @@ int MqttEncode_Subscribe(byte *tx_buf, int tx_buf_len,
12251244 byte * tx_payload ;
12261245 MqttTopic * topic ;
12271246#ifdef WOLFMQTT_V5
1228- word32 props_len = 0 ;
1247+ int props_len = 0 ;
12291248#endif
12301249
12311250 /* Validate required arguments */
@@ -1249,11 +1268,16 @@ int MqttEncode_Subscribe(byte *tx_buf, int tx_buf_len,
12491268#ifdef WOLFMQTT_V5
12501269 if (subscribe -> protocol_level >= MQTT_CONNECT_PROTOCOL_LEVEL_5 ) {
12511270 /* Determine length of properties */
1252- remain_len += props_len = MqttEncode_Props (MQTT_PACKET_TYPE_SUBSCRIBE ,
1271+ props_len = MqttEncode_Props (MQTT_PACKET_TYPE_SUBSCRIBE ,
12531272 subscribe -> props , NULL );
1273+ if (props_len >= 0 ) {
1274+ remain_len += props_len ;
12541275
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 );
12571281 }
12581282#endif
12591283
@@ -1374,7 +1398,7 @@ int MqttEncode_Unsubscribe(byte *tx_buf, int tx_buf_len,
13741398 byte * tx_payload ;
13751399 MqttTopic * topic ;
13761400#ifdef WOLFMQTT_V5
1377- word32 props_len = 0 ;
1401+ int props_len = 0 ;
13781402#endif
13791403
13801404 /* Validate required arguments */
@@ -1398,11 +1422,15 @@ int MqttEncode_Unsubscribe(byte *tx_buf, int tx_buf_len,
13981422#ifdef WOLFMQTT_V5
13991423 if (unsubscribe -> protocol_level >= MQTT_CONNECT_PROTOCOL_LEVEL_5 ) {
14001424 /* 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 );
14061434 }
14071435#endif
14081436
@@ -1563,7 +1591,7 @@ int MqttEncode_Disconnect(byte *tx_buf, int tx_buf_len,
15631591 int header_len ;
15641592 int remain_len = 0 ;
15651593#ifdef WOLFMQTT_V5
1566- word32 props_len = 0 ;
1594+ int props_len = 0 ;
15671595#endif
15681596
15691597 /* Validate required arguments */
@@ -1577,12 +1605,15 @@ int MqttEncode_Disconnect(byte *tx_buf, int tx_buf_len,
15771605
15781606 if (disconnect -> props != NULL ) {
15791607 /* 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 ,
15821609 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 );
15861617 }
15871618 if ((remain_len != 0 ) ||
15881619 (disconnect -> reason_code != MQTT_REASON_SUCCESS )) {
@@ -1695,7 +1726,7 @@ int MqttEncode_Auth(byte *tx_buf, int tx_buf_len, MqttAuth *auth)
16951726{
16961727 int header_len , remain_len = 0 ;
16971728 byte * tx_payload ;
1698- word32 props_len = 0 ;
1729+ int props_len = 0 ;
16991730
17001731 /* Validate required arguments */
17011732 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)
17061737 remain_len ++ ;
17071738
17081739 /* Determine length of properties */
1709- remain_len += props_len = MqttEncode_Props (MQTT_PACKET_TYPE_AUTH ,
1740+ props_len = MqttEncode_Props (MQTT_PACKET_TYPE_AUTH ,
17101741 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 );
17141749
17151750 /* Encode fixed header */
17161751 header_len = MqttEncode_FixedHeader (tx_buf , tx_buf_len , remain_len ,
0 commit comments