From 16fa111c765ed3664bd8d2f2c6917d949bd23364 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 4 Jul 2019 11:02:45 +0200 Subject: [PATCH 1/3] net/mqttsn: add min&max allowed len for client ID --- sys/include/net/mqttsn.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/include/net/mqttsn.h b/sys/include/net/mqttsn.h index a38c8eb916..1324320ae2 100644 --- a/sys/include/net/mqttsn.h +++ b/sys/include/net/mqttsn.h @@ -35,6 +35,16 @@ extern "C" { #define MQTTSN_DEFAULT_PORT (1883U) #endif +/** + * @name The client ID must contain 1-23 characters + * + * @see MQTT-SN spec v1.2, section 5.3.1 + * @{ + */ +#define MQTTSN_CLI_ID_MINLEN (1U) +#define MQTTSN_CLI_ID_MAXLEN (23U) +/** @} */ + /** * @brief MQTT-SN flags * From 785f59fb7ffe0222039aaad27fb136499cad56f3 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 4 Jul 2019 11:03:37 +0200 Subject: [PATCH 2/3] net/asymcute: make cli ID len conform to standard --- sys/include/net/asymcute.h | 11 +---------- sys/net/application_layer/asymcute/asymcute.c | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/sys/include/net/asymcute.h b/sys/include/net/asymcute.h index d468fb1b9c..65e806b2b4 100644 --- a/sys/include/net/asymcute.h +++ b/sys/include/net/asymcute.h @@ -95,15 +95,6 @@ extern "C" { #define ASYMCUTE_LISTENER_STACKSIZE (THREAD_STACKSIZE_DEFAULT) #endif -#ifndef ASYMCUTE_ID_MAXLEN -/** - * @brief Maximum client ID length - * - * @note Must be less than (256 - 8) and less than (ASYMCUTE_BUFSIZE - 8) - */ -#define ASYMCUTE_ID_MAXLEN (32U) -#endif - #ifndef ASYMCUTE_TOPIC_MAXLEN /** * @brief Maximum topic length @@ -273,7 +264,7 @@ struct asymcute_con { uint8_t keepalive_retry_cnt; /**< keep alive transmission counter */ uint8_t state; /**< connection state */ uint8_t rxbuf[ASYMCUTE_BUFSIZE]; /**< connection specific receive buf */ - char cli_id[ASYMCUTE_ID_MAXLEN + 1];/**< buffer to store client ID */ + char cli_id[MQTTSN_CLI_ID_MAXLEN + 1]; /**< buffer to store client ID */ }; /** diff --git a/sys/net/application_layer/asymcute/asymcute.c b/sys/net/application_layer/asymcute/asymcute.c index b3379820e8..10dbf2e515 100644 --- a/sys/net/application_layer/asymcute/asymcute.c +++ b/sys/net/application_layer/asymcute/asymcute.c @@ -712,7 +712,7 @@ int asymcute_connect(asymcute_con_t *con, asymcute_req_t *req, return ASYMCUTE_NOTSUP; } /* make sure the client ID will fit into the dedicated buffer */ - if (id_len > ASYMCUTE_ID_MAXLEN) { + if ((id_len < MQTTSN_CLI_ID_MINLEN) || (id_len > MQTTSN_CLI_ID_MAXLEN)) { return ASYMCUTE_OVERFLOW; } /* check if the context is not already connected to any gateway */ From eb50d4704af7f8f0b43a9dd87cc473e600029ba0 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 4 Jul 2019 11:04:22 +0200 Subject: [PATCH 3/3] net/emcute: make cli ID conform to standard --- sys/include/net/emcute.h | 10 ---------- sys/net/application_layer/emcute/emcute.c | 4 +++- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/sys/include/net/emcute.h b/sys/include/net/emcute.h index 1377b6089b..e2d0a7c1c9 100644 --- a/sys/include/net/emcute.h +++ b/sys/include/net/emcute.h @@ -114,16 +114,6 @@ extern "C" { #define EMCUTE_BUFSIZE (512U) #endif -#ifndef EMCUTE_ID_MAXLEN -/** - * @brief Maximum client ID length - * - * @note **Must** be less than (256 - 6) AND less than - * (@ref EMCUTE_BUFSIZE - 6). - */ -#define EMCUTE_ID_MAXLEN (196U) -#endif - #ifndef EMCUTE_TOPIC_MAXLEN /** * @brief Maximum topic length diff --git a/sys/net/application_layer/emcute/emcute.c b/sys/net/application_layer/emcute/emcute.c index 88efb31143..81ae2a7fe0 100644 --- a/sys/net/application_layer/emcute/emcute.c +++ b/sys/net/application_layer/emcute/emcute.c @@ -28,6 +28,7 @@ #include "thread_flags.h" #include "net/emcute.h" +#include "net/mqttsn.h" #include "emcute_internal.h" #define ENABLE_DEBUG (0) @@ -490,7 +491,8 @@ int emcute_willupd_msg(const void *data, size_t len) void emcute_run(uint16_t port, const char *id) { - assert(strlen(id) < EMCUTE_ID_MAXLEN); + assert(strlen(id) >= MQTTSN_CLI_ID_MINLEN && + strlen(id) <= MQTTSN_CLI_ID_MAXLEN); sock_udp_ep_t local = SOCK_IPV6_EP_ANY; sock_udp_ep_t remote;