lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] MQTT broken upgrading from 2.1.2 to 2.1.3


From: Jonathan D
Subject: [lwip-users] MQTT broken upgrading from 2.1.2 to 2.1.3
Date: Mon, 2 May 2022 13:46:29 +0000

Hello,

After upgrading LwIP from 2.1.2 to 2.1.3, the device is not able to connect to AWS IoT anymore.

I think the cause is this commit:
https://git.savannah.nongnu.org/cgit/lwip.git/commit/?id=67350e3c01b349a3795d4ca905695968500ce482

Specifically, this part is giving trouble :
---
--- a/LwIP/src/apps/mqtt/mqtt.c
+++ b/LwIP/src/apps/mqtt/mqtt.c
@@ -887,19 +887,17 @@ mqtt_parse_incoming(mqtt_client_t *client, struct pbuf *p)
       }
     } else {
       /* Fixed header has been parsed, parse variable header */
-      u16_t cpy_len, cpy_start, buffer_space;
-
-      cpy_start = (client->msg_idx - fixed_hdr_len) % (MQTT_VAR_HEADER_BUFFER_LEN - fixed_hdr_len) + fixed_hdr_len;
+      u16_t cpy_len, buffer_space;

       /* Allow to copy the lesser one of available length in input data or bytes remaining in message */
       cpy_len = (u16_t)LWIP_MIN((u16_t)(p->tot_len - in_offset), msg_rem_len);

       /* Limit to available space in buffer */
-      buffer_space = MQTT_VAR_HEADER_BUFFER_LEN - cpy_start;
+      buffer_space = MQTT_VAR_HEADER_BUFFER_LEN - fixed_hdr_len;
       if (cpy_len > buffer_space) {
         cpy_len = buffer_space;
       }
-      pbuf_copy_partial(p, client->rx_buffer + cpy_start, cpy_len, in_offset);
+      pbuf_copy_partial(p, client->rx_buffer + fixed_hdr_len, cpy_len, in_offset);

       /* Advance get and put indexes  */
       client->msg_idx += cpy_len;
@@ -909,7 +907,7 @@ mqtt_parse_incoming(mqtt_client_t *client, struct pbuf *p)
       LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_parse_incoming: msg_idx: %"U32_F", cpy_len: %"U16_F", remaining %"U32_F"\n", client->msg_idx, cpy_len, msg_rem_len));
       if ((msg_rem_len == 0) || (cpy_len == buffer_space)) {
         /* Whole message received or buffer is full */
-        mqtt_connection_status_t res = mqtt_message_received(client, fixed_hdr_len, (cpy_start + cpy_len) - fixed_hdr_len, msg_rem_len);
+        mqtt_connection_status_t res = mqtt_message_received(client, fixed_hdr_len, cpy_len, msg_rem_len);
         if (res != MQTT_CONNECT_ACCEPTED) {
           return res;
         }
---

Because indexes are changed in `mqtt_message_received`, `var_hdr_payload` doesn't start at the correct position and
```
      topic_len = var_hdr_payload[0];
      topic_len = (topic_len << 8) + (u16_t)(var_hdr_payload[1]);
```
becomes totally irrelevant.

Do someone have the same issue ?

Thank you

reply via email to

[Prev in Thread] Current Thread [Next in Thread]