From 32ed4809ed1e013f4214e3646d6e1dedaed89a8f Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 11 Aug 2020 16:12:18 +0100 Subject: [PATCH 01/10] Build fix for NetBSD. Thanks to Greg Troxel. --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 053ca1d9..92ff0ca2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -152,6 +152,8 @@ if (UNIX) set (MOSQ_LIBS ${MOSQ_LIBS} dl m) elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") set (MOSQ_LIBS ${MOSQ_LIBS} m) + elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") + set (MOSQ_LIBS ${MOSQ_LIBS} m) elseif(QNX) set(MOSQ_LIBS ${MOSQ_LIBS} m socket) else(APPLE) From 9929ce0a26e3b66349286d778587dbb7239f2d91 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 12 Aug 2020 09:44:42 +0100 Subject: [PATCH 02/10] All clients exit with an error exit code on CONNACK failure. Closes #1778. Thanks to jflambert. --- ChangeLog.txt | 4 +++ client/pub_client.c | 9 +++++- client/rr_client.c | 8 +++++- client/sub_client.c | 8 +++++- man/mosquitto_passwd.1.xml | 58 ++++++++++++++++++++++++++++++++++++++ man/mosquitto_pub.1.xml | 58 ++++++++++++++++++++++++++++++++++++++ man/mosquitto_sub.1.xml | 58 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 200 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 1630e251..f67fc472 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,7 @@ +Clients: +- All clients exit with an error exit code on CONNACK failure. Closes #1778. + + 1.6.11 - 2020-08-11 =================== diff --git a/client/pub_client.c b/client/pub_client.c index ef0bf16e..3b0078a8 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -46,6 +46,7 @@ static bool disconnect_sent = false; static int publish_count = 0; static bool ready_for_repeat = false; static volatile int status = STATUS_CONNECTING; +static int connack_result = 0; #ifdef WIN32 static uint64_t next_publish_tv; @@ -129,6 +130,8 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag UNUSED(flags); UNUSED(properties); + connack_result = result; + if(!result){ switch(cfg.pub_mode){ case MSGMODE_CMD: @@ -555,7 +558,11 @@ int main(int argc, char *argv[]) if(rc){ err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc)); } - return rc; + if(connack_result){ + return connack_result; + }else{ + return rc; + } cleanup: mosquitto_lib_cleanup(); diff --git a/client/rr_client.c b/client/rr_client.c index 4e22fa3b..dec94686 100644 --- a/client/rr_client.c +++ b/client/rr_client.c @@ -52,6 +52,7 @@ extern struct mosq_config cfg; bool process_messages = true; int msg_count = 0; struct mosquitto *mosq = NULL; +static int connack_result = 0; #ifndef WIN32 void my_signal_handler(int signum) @@ -117,6 +118,7 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flags, const mosquitto_property *properties) { + connack_result = result; if(!result){ client_state = rr_s_connected; mosquitto_subscribe_v5(mosq, NULL, cfg.response_topic, cfg.qos, 0, cfg.subscribe_props); @@ -363,7 +365,11 @@ int main(int argc, char *argv[]) if(rc){ err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc)); } - return rc; + if(connack_result){ + return connack_result; + }else{ + return rc; + } cleanup: mosquitto_lib_cleanup(); diff --git a/client/sub_client.c b/client/sub_client.c index 7eeaae59..fb26638f 100644 --- a/client/sub_client.c +++ b/client/sub_client.c @@ -40,6 +40,7 @@ bool process_messages = true; int msg_count = 0; struct mosquitto *mosq = NULL; int last_mid = 0; +static int connack_result = 0; #ifndef WIN32 void my_signal_handler(int signum) @@ -117,6 +118,7 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag UNUSED(flags); UNUSED(properties); + connack_result = result; if(!result){ mosquitto_subscribe_multiple(mosq, NULL, cfg.topic_count, cfg.topics, cfg.qos, cfg.sub_opts, cfg.subscribe_props); @@ -371,7 +373,11 @@ int main(int argc, char *argv[]) if(rc){ err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc)); } - return rc; + if(connack_result){ + return connack_result; + }else{ + return rc; + } cleanup: mosquitto_destroy(mosq); diff --git a/man/mosquitto_passwd.1.xml b/man/mosquitto_passwd.1.xml index 5f144bf9..3c0abd3f 100644 --- a/man/mosquitto_passwd.1.xml +++ b/man/mosquitto_passwd.1.xml @@ -109,6 +109,64 @@ + + Exit Status + + mosquitto_sub returns zero on success, or non-zero on error. If + the connection is refused by the broker at the MQTT level, then + the exit code is the CONNACK reason code. If another error + occurs, the exit code is a libmosquitto return value. + + + MQTT v3.1.1 CONNACK codes: + + Success + Connection refused: Bad protocol version + Connection refused: Identifier rejected + Connection refused: Server unavailable + Connection refused: Bad username/password + Connection refused: Not authorized + + + MQTT v5 CONNACK codes: + + Success + Unspecified error + Malformed packet + Protocol error + Implementation specific error + Unsupported protocol version + Client ID not valid + Bad username or password + Not authorized + Server unavailable + Server busy + Banned + Server shutting down + Bad authentication method + Keep alive timeout + Session taken over + Topic filter invalid + Topic name invalid + Receive maximum exceeded + Topic alias invalid + Packet too large + Message rate too high + Quota exceeded + Administrative action + Payload format invalid + Retain not supported + QoS not supported + Use another server + Server moved + Shared subscriptions not supported + Connection rate exceeded + Maximum connect time + Subscription IDs not supported + Wildcard subscriptions not supported + + + Examples Add a user to a new password file: diff --git a/man/mosquitto_pub.1.xml b/man/mosquitto_pub.1.xml index a05a938f..58991749 100644 --- a/man/mosquitto_pub.1.xml +++ b/man/mosquitto_pub.1.xml @@ -654,6 +654,64 @@ + + Exit Status + + mosquitto_sub returns zero on success, or non-zero on error. If + the connection is refused by the broker at the MQTT level, then + the exit code is the CONNACK reason code. If another error + occurs, the exit code is a libmosquitto return value. + + + MQTT v3.1.1 CONNACK codes: + + Success + Connection refused: Bad protocol version + Connection refused: Identifier rejected + Connection refused: Server unavailable + Connection refused: Bad username/password + Connection refused: Not authorized + + + MQTT v5 CONNACK codes: + + Success + Unspecified error + Malformed packet + Protocol error + Implementation specific error + Unsupported protocol version + Client ID not valid + Bad username or password + Not authorized + Server unavailable + Server busy + Banned + Server shutting down + Bad authentication method + Keep alive timeout + Session taken over + Topic filter invalid + Topic name invalid + Receive maximum exceeded + Topic alias invalid + Packet too large + Message rate too high + Quota exceeded + Administrative action + Payload format invalid + Retain not supported + QoS not supported + Use another server + Server moved + Shared subscriptions not supported + Connection rate exceeded + Maximum connect time + Subscription IDs not supported + Wildcard subscriptions not supported + + + Examples Publish temperature information to localhost with QoS 1: diff --git a/man/mosquitto_sub.1.xml b/man/mosquitto_sub.1.xml index 55867c7e..2e7e4bd6 100644 --- a/man/mosquitto_sub.1.xml +++ b/man/mosquitto_sub.1.xml @@ -893,6 +893,64 @@ mosquitto_sub -t 'bbc/#' -T bbc/bbc1 --remove-retained + + Exit Status + + mosquitto_sub returns zero on success, or non-zero on error. If + the connection is refused by the broker at the MQTT level, then + the exit code is the CONNACK reason code. If another error + occurs, the exit code is a libmosquitto return value. + + + MQTT v3.1.1 CONNACK codes: + + Success + Connection refused: Bad protocol version + Connection refused: Identifier rejected + Connection refused: Server unavailable + Connection refused: Bad username/password + Connection refused: Not authorized + + + MQTT v5 CONNACK codes: + + Success + Unspecified error + Malformed packet + Protocol error + Implementation specific error + Unsupported protocol version + Client ID not valid + Bad username or password + Not authorized + Server unavailable + Server busy + Banned + Server shutting down + Bad authentication method + Keep alive timeout + Session taken over + Topic filter invalid + Topic name invalid + Receive maximum exceeded + Topic alias invalid + Packet too large + Message rate too high + Quota exceeded + Administrative action + Payload format invalid + Retain not supported + QoS not supported + Use another server + Server moved + Shared subscriptions not supported + Connection rate exceeded + Maximum connect time + Subscription IDs not supported + Wildcard subscriptions not supported + + + Examples Note that these really are examples - the subscriptions will work From a224a8f217a0428e1ad85f9a92760af5f0a06258 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 13 Aug 2020 14:32:47 +0100 Subject: [PATCH 03/10] Don't busy loop with `mosquitto_pub -l` on a slow connection. --- ChangeLog.txt | 1 + client/pub_client.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index f67fc472..a762ff9e 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,6 @@ Clients: - All clients exit with an error exit code on CONNACK failure. Closes #1778. +- Don't busy loop with `mosquitto_pub -l` on a slow connection. 1.6.11 - 2020-08-11 diff --git a/client/pub_client.c b/client/pub_client.c index 3b0078a8..b39c700a 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -235,6 +235,17 @@ int pub_stdin_line_loop(struct mosquitto *mosq) mosquitto_loop_start(mosq); stdin_finished = false; do{ + if(status == STATUS_CONNECTING){ +#ifdef WIN32 + Sleep(100); +#else + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 100000000; + nanosleep(&ts, NULL); +#endif + } + if(status == STATUS_CONNACK_RECVD){ pos = 0; read_len = line_buf_len; From d254ea70dfe5c3fd7df1bab4c0a0457e2ab7b74d Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Tue, 18 Aug 2020 21:06:14 +0000 Subject: [PATCH 04/10] docs: remove duplicate mosquitto_reconnect_delay_set Was listed in both client options, and under the callbacks. Signed-off-by: Karl Palsson --- lib/mosquitto.h | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 9d3557d6..262c523e 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -2097,43 +2097,6 @@ libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on libmosq_EXPORT int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, const char *value); -/* - * Function: mosquitto_reconnect_delay_set - * - * Control the behaviour of the client when it has unexpectedly disconnected in - * or after . The default - * behaviour if this function is not used is to repeatedly attempt to reconnect - * with a delay of 1 second until the connection succeeds. - * - * Use reconnect_delay parameter to change the delay between successive - * reconnection attempts. You may also enable exponential backoff of the time - * between reconnections by setting reconnect_exponential_backoff to true and - * set an upper bound on the delay with reconnect_delay_max. - * - * Example 1: - * delay=2, delay_max=10, exponential_backoff=False - * Delays would be: 2, 4, 6, 8, 10, 10, ... - * - * Example 2: - * delay=3, delay_max=30, exponential_backoff=True - * Delays would be: 3, 6, 12, 24, 30, 30, ... - * - * Parameters: - * mosq - a valid mosquitto instance. - * reconnect_delay - the number of seconds to wait between - * reconnects. - * reconnect_delay_max - the maximum number of seconds to wait - * between reconnects. - * reconnect_exponential_backoff - use exponential backoff between - * reconnect attempts. Set to true to enable - * exponential backoff. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - */ -libmosq_EXPORT int mosquitto_reconnect_delay_set(struct mosquitto *mosq, unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff); - /* ============================================================================= * From 2fdb5a01715834d714f1be7307e4eda4772173f9 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Tue, 18 Aug 2020 21:07:03 +0000 Subject: [PATCH 05/10] docs: move _string_option with rest of client options It was grouped with the callbacks, where it didn't make a lot of sense. Signed-off-by: Karl Palsson --- lib/mosquitto.h | 67 ++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 262c523e..93793fa5 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -1511,6 +1511,39 @@ libmosq_EXPORT int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t */ libmosq_EXPORT int mosquitto_void_option(struct mosquitto *mosq, enum mosq_opt_t option, void *value); +/* + * Function: mosquitto_string_option + * + * Used to set const char* options for the client. + * + * Parameters: + * mosq - a valid mosquitto instance. + * option - the option to set. + * value - the option specific value. + * + * Options: + * MOSQ_OPT_TLS_ENGINE + * Configure the client for TLS Engine support. Pass a TLS Engine ID + * to be used when creating TLS connections. + * Must be set before . + * MOSQ_OPT_TLS_KEYFORM + * Configure the client to treat the keyfile differently depending + * on its type. Must be set before . + * Set as either "pem" or "engine", to determine from where the + * private key for a TLS connection will be obtained. Defaults to + * "pem", a normal private key file. + * MOSQ_OPT_TLS_KPASS_SHA1 + * Where the TLS Engine requires the use of a password to be + * accessed, this option allows a hex encoded SHA1 hash of the + * private key password to be passed to the engine directly. + * Must be set before . + * MOSQ_OPT_TLS_ALPN + * If the broker being connected to has multiple services available + * on a single TLS port, such as both MQTT and WebSockets, use this + * option to configure the ALPN option for the connection. + */ +libmosq_EXPORT int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, const char *value); + /* * Function: mosquitto_reconnect_delay_set @@ -2063,40 +2096,6 @@ libmosq_EXPORT void mosquitto_unsubscribe_v5_callback_set(struct mosquitto *mosq */ libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on_log)(struct mosquitto *, void *, int, const char *)); -/* - * Function: mosquitto_string_option - * - * Used to set const char* options for the client. - * - * Parameters: - * mosq - a valid mosquitto instance. - * option - the option to set. - * value - the option specific value. - * - * Options: - * MOSQ_OPT_TLS_ENGINE - * Configure the client for TLS Engine support. Pass a TLS Engine ID - * to be used when creating TLS connections. - * Must be set before . - * MOSQ_OPT_TLS_KEYFORM - * Configure the client to treat the keyfile differently depending - * on its type. Must be set before . - * Set as either "pem" or "engine", to determine from where the - * private key for a TLS connection will be obtained. Defaults to - * "pem", a normal private key file. - * MOSQ_OPT_TLS_KPASS_SHA1 - * Where the TLS Engine requires the use of a password to be - * accessed, this option allows a hex encoded SHA1 hash of the - * private key password to be passed to the engine directly. - * Must be set before . - * MOSQ_OPT_TLS_ALPN - * If the broker being connected to has multiple services available - * on a single TLS port, such as both MQTT and WebSockets, use this - * option to configure the ALPN option for the connection. - */ -libmosq_EXPORT int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, const char *value); - - /* ============================================================================= * From 79051fbdca3a137d5ef000bec3edfe93eaa4c224 Mon Sep 17 00:00:00 2001 From: Titouan Christophe Date: Tue, 18 Aug 2020 01:26:58 +0200 Subject: [PATCH 06/10] do not include pthread when compiling without threading support This fixes the following error, when compiling for systems without pthread support, and when passing WITH_THREADING=no to make: thread_mosq.c:24:12: fatal error: pthread.h: No such file or directory # include ^~~~~~~~~~~ compilation terminated. Signed-off-by: Titouan Christophe --- lib/thread_mosq.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/thread_mosq.c b/lib/thread_mosq.c index b05c1d2a..46e19807 100644 --- a/lib/thread_mosq.c +++ b/lib/thread_mosq.c @@ -20,11 +20,13 @@ Contributors: #include #endif +#if defined(WITH_THREADING) #if defined(__linux__) || defined(__NetBSD__) # include #elif defined(__FreeBSD__) || defined(__OpenBSD__) # include #endif +#endif #include "mosquitto_internal.h" #include "net_mosq.h" From 4dc835b73d352a4a67ee1a57f70d7a1b8a88003a Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 19 Aug 2020 11:12:05 +0100 Subject: [PATCH 07/10] Fix possible memory leaks on errors during persistence write. --- src/persist_write_v5.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/persist_write_v5.c b/src/persist_write_v5.c index 48ca9c93..10d51456 100644 --- a/src/persist_write_v5.c +++ b/src/persist_write_v5.c @@ -115,7 +115,10 @@ int persist__chunk_client_msg_write_v6(FILE *db_fptr, struct P_client_msg *chunk return MOSQ_ERR_NOMEM; } rc = property__write_all(&prop_packet, chunk->properties, true); - if(rc) return rc; + if(rc){ + mosquitto__free(prop_packet.payload); + return rc; + } write_e(db_fptr, prop_packet.payload, proplen); mosquitto__free(prop_packet.payload); @@ -179,7 +182,10 @@ int persist__chunk_message_store_write_v6(FILE *db_fptr, struct P_msg_store *chu return MOSQ_ERR_NOMEM; } rc = property__write_all(&prop_packet, chunk->properties, true); - if(rc) return rc; + if(rc){ + mosquitto__free(prop_packet.payload); + return rc; + } write_e(db_fptr, prop_packet.payload, proplen); mosquitto__free(prop_packet.payload); From b3b58cc6357336eb23da73922d3ef971998689ab Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 19 Aug 2020 14:04:02 +0100 Subject: [PATCH 08/10] Build warning fixes. --- ChangeLog.txt | 3 +++ src/conf.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index a762ff9e..33646461 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,6 @@ +Broker: +- Build warning fixes when building with WITH_BRIDGE=no and WITH_TLS=no. + Clients: - All clients exit with an error exit code on CONNACK failure. Closes #1778. - Don't busy loop with `mosquitto_pub -l` on a slow connection. diff --git a/src/conf.c b/src/conf.c index 6ec461ed..9d31ad9b 100644 --- a/src/conf.c +++ b/src/conf.c @@ -760,6 +760,7 @@ int config__read(struct mosquitto_db *db, struct mosquitto__config *config, bool } +#ifdef WITH_BRIDGE static int config__create_bridge_remap_topic(const char *prefix, const char *topic, char **remap_topic) { int len; @@ -827,6 +828,7 @@ static int config__create_bridge_prefix(char **prefix, const char *topic, const return MOSQ_ERR_SUCCESS; } +#endif int config__read_file_core(struct mosquitto__config *config, bool reload, struct config_recurse *cr, int level, int *lineno, FILE *fptr, char **buf, int *buflen) @@ -849,8 +851,10 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct int lineno_ext = 0; char **files; int file_count; +#ifdef WITH_TLS char *kpass_sha = NULL, *kpass_sha_bin = NULL; char *keyform ; +#endif *lineno = 0; From c1b009e4dfa0644282037e432400bf537948f868 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 19 Aug 2020 14:05:27 +0100 Subject: [PATCH 09/10] Fix memory leak on handling QoS 2 PUBLISH. In some circumstances, Mosquitto could leak memory when handling PUBLISH messages. This is limited to incoming QoS 2 messages, and is related to the combination of the broker having persistence enabled, a clean session=false client, which was connected prior to the broker restarting, then has reconnected and has now sent messages at a sufficiently high rate that the incoming queue at the broker has filled up and hence messages are being dropped. This is more likely to have an effect where max_queued_messages is a small value. This has now been fixed. Closes #1793. Thanks to mbates14. --- ChangeLog.txt | 13 +++++++++++++ src/database.c | 4 ++-- src/handle_publish.c | 20 +++++++++++++++----- src/mosquitto_broker_internal.h | 2 ++ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 33646461..c7dcb03f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,16 @@ +1.6.12 - 2020-08-19 +=================== + +Security: +- In some circumstances, Mosquitto could leak memory when handling PUBLISH + messages. This is limited to incoming QoS 2 messages, and is related + to the combination of the broker having persistence enabled, a clean + session=false client, which was connected prior to the broker restarting, + then has reconnected and has now sent messages at a sufficiently high rate + that the incoming queue at the broker has filled up and hence messages are + being dropped. This is more likely to have an effect where + max_queued_messages is a small value. This has now been fixed. Closes #1793. + Broker: - Build warning fixes when building with WITH_BRIDGE=no and WITH_TLS=no. diff --git a/src/database.c b/src/database.c index 124824cd..1e58f05d 100644 --- a/src/database.c +++ b/src/database.c @@ -37,7 +37,7 @@ static unsigned long max_queued_bytes = 0; * @param qos qos for the packet of interest * @return true if more in flight are allowed. */ -static bool db__ready_for_flight(struct mosquitto_msg_data *msgs, int qos) +bool db__ready_for_flight(struct mosquitto_msg_data *msgs, int qos) { bool valid_bytes; bool valid_count; @@ -68,7 +68,7 @@ static bool db__ready_for_flight(struct mosquitto_msg_data *msgs, int qos) * @param qos destination qos for the packet of interest * @return true if queuing is allowed, false if should be dropped */ -static bool db__ready_for_queue(struct mosquitto *context, int qos, struct mosquitto_msg_data *msg_data) +bool db__ready_for_queue(struct mosquitto *context, int qos, struct mosquitto_msg_data *msg_data) { int source_count; int adjust_count; diff --git a/src/handle_publish.c b/src/handle_publish.c index acbbec93..610a7ad8 100644 --- a/src/handle_publish.c +++ b/src/handle_publish.c @@ -302,12 +302,21 @@ int handle__publish(struct mosquitto_db *db, struct mosquitto *context) db__message_store_find(context, mid, &stored); } if(!stored){ - dup = 0; - if(db__message_store(db, context, mid, topic, qos, payloadlen, &payload, retain, &stored, message_expiry_interval, msg_properties, 0, mosq_mo_client)){ - mosquitto_property_free_all(&msg_properties); - return 1; + if(qos == 0 + || db__ready_for_flight(&context->msgs_in, qos) + || db__ready_for_queue(context, qos, &context->msgs_in)){ + + dup = 0; + if(db__message_store(db, context, mid, topic, qos, payloadlen, &payload, retain, &stored, message_expiry_interval, msg_properties, 0, mosq_mo_client)){ + mosquitto_property_free_all(&msg_properties); + return 1; + } + msg_properties = NULL; /* Now belongs to db__message_store() */ + }else{ + /* Client isn't allowed any more incoming messages, so fail early */ + reason_code = MQTT_RC_QUOTA_EXCEEDED; + goto process_bad_message; } - msg_properties = NULL; /* Now belongs to db__message_store() */ }else{ mosquitto__free(topic); topic = stored->topic; @@ -340,6 +349,7 @@ int handle__publish(struct mosquitto_db *db, struct mosquitto *context) } /* db__message_insert() returns 2 to indicate dropped message * due to queue. This isn't an error so don't disconnect them. */ + /* FIXME - this is no longer necessary due to failing early above */ if(!res){ if(send__pubrec(context, mid, 0)) rc = 1; }else if(res == 1){ diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 1e0c42c6..ba42bafa 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -629,6 +629,8 @@ void db__msg_store_ref_dec(struct mosquitto_db *db, struct mosquitto_msg_store * void db__msg_store_clean(struct mosquitto_db *db); void db__msg_store_compact(struct mosquitto_db *db); int db__message_reconnect_reset(struct mosquitto_db *db, struct mosquitto *context); +bool db__ready_for_flight(struct mosquitto_msg_data *msgs, int qos); +bool db__ready_for_queue(struct mosquitto *context, int qos, struct mosquitto_msg_data *msg_data); void sys_tree__init(struct mosquitto_db *db); void sys_tree__update(struct mosquitto_db *db, int interval, time_t start_time); From 39ff7226eb675f66edf56c32a9249aa582278e01 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 19 Aug 2020 14:46:44 +0100 Subject: [PATCH 10/10] Bump version, add new www posts. --- CMakeLists.txt | 2 +- config.mk | 2 +- installer/mosquitto.nsi | 2 +- installer/mosquitto64.nsi | 2 +- lib/mosquitto.h | 2 +- set-version.sh | 2 +- snap/snapcraft.yaml | 2 +- www/pages/download.md | 8 ++--- www/posts/2020/08/version-1-6-12-released.md | 32 ++++++++++++++++++++ 9 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 www/posts/2020/08/version-1-6-12-released.md diff --git a/CMakeLists.txt b/CMakeLists.txt index 92604490..27c08c58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ project(mosquitto) cmake_minimum_required(VERSION 2.8) # Only for version 3 and up. cmake_policy(SET CMP0042 NEW) -set (VERSION 1.6.11) +set (VERSION 1.6.12) add_definitions (-DCMAKE -DVERSION=\"${VERSION}\") diff --git a/config.mk b/config.mk index 75c8b35f..80e02f96 100644 --- a/config.mk +++ b/config.mk @@ -109,7 +109,7 @@ WITH_COVERAGE:=no # Also bump lib/mosquitto.h, CMakeLists.txt, # installer/mosquitto.nsi, installer/mosquitto64.nsi -VERSION=1.6.11 +VERSION=1.6.12 # Client library SO version. Bump if incompatible API/ABI changes are made. SOVERSION=1 diff --git a/installer/mosquitto.nsi b/installer/mosquitto.nsi index 6cd04601..60ac9a26 100644 --- a/installer/mosquitto.nsi +++ b/installer/mosquitto.nsi @@ -9,7 +9,7 @@ !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' Name "Eclipse Mosquitto" -!define VERSION 1.6.11 +!define VERSION 1.6.12 OutFile "mosquitto-${VERSION}-install-windows-x86.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/installer/mosquitto64.nsi b/installer/mosquitto64.nsi index dc54654b..c303f7a4 100644 --- a/installer/mosquitto64.nsi +++ b/installer/mosquitto64.nsi @@ -9,7 +9,7 @@ !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' Name "Eclipse Mosquitto" -!define VERSION 1.6.11 +!define VERSION 1.6.12 OutFile "mosquitto-${VERSION}-install-windows-x64.exe" !include "x64.nsh" diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 93793fa5..88abaead 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -48,7 +48,7 @@ extern "C" { #define LIBMOSQUITTO_MAJOR 1 #define LIBMOSQUITTO_MINOR 6 -#define LIBMOSQUITTO_REVISION 11 +#define LIBMOSQUITTO_REVISION 12 /* LIBMOSQUITTO_VERSION_NUMBER looks like 1002001 for e.g. version 1.2.1. */ #define LIBMOSQUITTO_VERSION_NUMBER (LIBMOSQUITTO_MAJOR*1000000+LIBMOSQUITTO_MINOR*1000+LIBMOSQUITTO_REVISION) diff --git a/set-version.sh b/set-version.sh index c98f34bd..c27c55bb 100755 --- a/set-version.sh +++ b/set-version.sh @@ -2,7 +2,7 @@ MAJOR=1 MINOR=6 -REVISION=11 +REVISION=12 sed -i "s/^VERSION=.*/VERSION=${MAJOR}.${MINOR}.${REVISION}/" config.mk diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a8ba134a..694a6c26 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: mosquitto -version: 1.6.11 +version: 1.6.12 summary: Eclipse Mosquitto MQTT broker description: This is a message broker that supports version 5.0, 3.1.1, and 3.1 of the MQTT protocol. diff --git a/www/pages/download.md b/www/pages/download.md index 2e805643..4619a7b4 100644 --- a/www/pages/download.md +++ b/www/pages/download.md @@ -1,7 +1,7 @@ + +Mosquitto 1.6.12 has been released, this is a bugfix release. + +# Security +- In some circumstances, Mosquitto could leak memory when handling PUBLISH + messages. This is limited to incoming QoS 2 messages, and is related + to the combination of the broker having persistence enabled, a clean + session=false client, which was connected prior to the broker restarting, + then has reconnected and has now sent messages at a sufficiently high rate + that the incoming queue at the broker has filled up and hence messages are + being dropped. This is more likely to have an effect where + `max_queued_messages` is a small value. This has now been fixed. Closes [#1793]. + +# Broker +- Build warning fixes when building with `WITH_BRIDGE=no` and `WITH_TLS=no`. + +# Clients +- All clients exit with an error exit code on CONNACK failure. Closes [#1778]. +- Don't busy loop with `mosquitto_pub -l` on a slow connection. + +[#1778]: https://github.com/eclipse/mosquitto/issues/1778 +[#1793]: https://github.com/eclipse/mosquitto/issues/1793