From 0691935ed9d45fb14713d20c1e5421b326383d2c Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 31 Oct 2024 23:06:48 +0000 Subject: [PATCH] Fix RESERVED packets not being quickly rejected. Closes #2325 --- ChangeLog.txt | 4 ++++ include/mqtt_protocol.h | 1 + lib/packet_mosq.c | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 0b706d90bd..1f235b6701 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,10 @@ 2.0.21 - 2024-xx-xx =================== +Broker: +- Fix clients sending a RESERVED packet not being quickly disconnected. + Closes #2325. + Client library: - Fix threads linking on Windows for static libmosquitto library Closes #3143 diff --git a/include/mqtt_protocol.h b/include/mqtt_protocol.h index ac86787739..ef05379d3f 100644 --- a/include/mqtt_protocol.h +++ b/include/mqtt_protocol.h @@ -34,6 +34,7 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause /* Message types */ +#define CMD_RESERVED 0x00U #define CMD_CONNECT 0x10U #define CMD_CONNACK 0x20U #define CMD_PUBLISH 0x30U diff --git a/lib/packet_mosq.c b/lib/packet_mosq.c index b063eb718e..2ea41b0e8e 100644 --- a/lib/packet_mosq.c +++ b/lib/packet_mosq.c @@ -395,6 +395,11 @@ int packet__read(struct mosquitto *mosq) /* Clients must send CONNECT as their first command. */ if(!(mosq->bridge) && state == mosq_cs_new && (byte&0xF0) != CMD_CONNECT){ return MOSQ_ERR_PROTOCOL; + }else if((byte&0xF0) == CMD_RESERVED){ + if(mosq->protocol == mosq_p_mqtt5){ + send__disconnect(mosq, MQTT_RC_PROTOCOL_ERROR, NULL); + } + return MOSQ_ERR_PROTOCOL; } #endif }else{