From 0189e7b02f4ac7bdd75b9b2df5cc5ba7e92b8eed Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Thu, 13 Sep 2018 14:54:49 +0200 Subject: [PATCH] mqtt: allow user + pass longer than 255 chars See bug #54655: "MQTT brokers such as Google Cloud IoT Core requires MQTT clients to send JSON Web Token (JWT) as password field of the MQTT Connect packet. JWT can be more than 255 bytes. Currently, the MQTT library restricts password to be less than 256 bytes, thus it prevents connectivity to Google Cloud IoT Core." Fix that by just converting the local variables for these from u8_t to u16_t. Suggested-by: Richmond Umagat Signed-off-by: Simon Goldschmidt --- src/apps/mqtt/mqtt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/apps/mqtt/mqtt.c b/src/apps/mqtt/mqtt.c index 3dc6fb01..6c10bc05 100644 --- a/src/apps/mqtt/mqtt.c +++ b/src/apps/mqtt/mqtt.c @@ -1289,7 +1289,7 @@ mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port, /* Length is the sum of 2+"MQTT", protocol level, flags and keep alive */ u16_t remaining_length = 2 + 4 + 1 + 1 + 2; u8_t flags = 0, will_topic_len = 0, will_msg_len = 0; - u8_t client_user_len = 0, client_pass_len = 0; + u16_t client_user_len = 0, client_pass_len = 0; LWIP_ASSERT_CORE_LOCKED(); LWIP_ASSERT("mqtt_client_connect: client != NULL", client != NULL); @@ -1330,9 +1330,9 @@ mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port, if (client_info->client_user != NULL) { flags |= MQTT_CONNECT_FLAG_USERNAME; len = strlen(client_info->client_user); - LWIP_ERROR("mqtt_client_connect: client_info->client_user length overflow", len <= 0xFF, return ERR_VAL); + LWIP_ERROR("mqtt_client_connect: client_info->client_user length overflow", len <= 0xFFFF, return ERR_VAL); LWIP_ERROR("mqtt_client_connect: client_info->client_user length must be > 0", len > 0, return ERR_VAL); - client_user_len = (u8_t)len; + client_user_len = (u16_t)len; len = remaining_length + 2 + client_user_len; LWIP_ERROR("mqtt_client_connect: remaining_length overflow", len <= 0xFFFF, return ERR_VAL); remaining_length = (u16_t)len; @@ -1340,9 +1340,9 @@ mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port, if (client_info->client_pass != NULL) { flags |= MQTT_CONNECT_FLAG_PASSWORD; len = strlen(client_info->client_pass); - LWIP_ERROR("mqtt_client_connect: client_info->client_pass length overflow", len <= 0xFF, return ERR_VAL); + LWIP_ERROR("mqtt_client_connect: client_info->client_pass length overflow", len <= 0xFFFF, return ERR_VAL); LWIP_ERROR("mqtt_client_connect: client_info->client_pass length must be > 0", len > 0, return ERR_VAL); - client_pass_len = (u8_t)len; + client_pass_len = (u16_t)len; len = remaining_length + 2 + client_pass_len; LWIP_ERROR("mqtt_client_connect: remaining_length overflow", len <= 0xFFFF, return ERR_VAL); remaining_length = (u16_t)len;