From 87579e0caca9ec637053e0f59a7c1f965935ae7f Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sat, 31 May 2014 21:53:35 +0100 Subject: [PATCH] Remove STRICT_PROTOCOL #ifdefs. --- ChangeLog.txt | 2 ++ config.mk | 14 --------- lib/read_handle_client.c | 5 ---- lib/read_handle_shared.c | 30 ------------------- src/read_handle_client.c | 5 ---- src/read_handle_server.c | 4 --- test/broker/01-connect-invalid-id-24.py | 39 ------------------------- test/broker/Makefile | 3 -- 8 files changed, 2 insertions(+), 100 deletions(-) delete mode 100755 test/broker/01-connect-invalid-id-24.py diff --git a/ChangeLog.txt b/ChangeLog.txt index 6ca959d6..0d7e1e35 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -9,6 +9,7 @@ Broker: - Fix bug #1324411, which could have had unexpected consequences for delayed messages in rare circumstances. - Add support for "session present" in CONNACK messages for MQTT v3.1.1. +- Remove strict protocol #ifdefs. Clients: - Both clients can now load default configuration options from a file. @@ -29,6 +30,7 @@ Client library: - Fix callback deadlocks after calling mosquitto_disconnect(), when using the threaded interfaces. Closes bug #1313725. - Fix SRV support when building with CMake. +- Remove strict protocol #ifdefs. General: - Use $(STRIP) for stripping binaries when installing, to allow easier cross diff --git a/config.mk b/config.mk index 4830bef9..4b9f5827 100644 --- a/config.mk +++ b/config.mk @@ -28,15 +28,6 @@ WITH_TLS_PSK:=yes # Comment out to disable client client threading support. WITH_THREADING:=yes -# Uncomment to compile the broker with strict protocol support. This means that -# both the client library and the broker will be very strict about protocol -# compliance on incoming data. Neither of them will return an error on -# incorrect "remaining length" values if this is commented out. The old -# behaviour (prior to 0.12) is equivalent to compiling with -# WITH_STRICT_PROTOCOL defined and means that clients will be immediately -# disconnected from the broker on non-compliance. -#WITH_STRICT_PROTOCOL:=yes - # Comment out to remove bridge support from the broker. This allow the broker # to connect to other brokers and subscribe/publish to topics. You probably # want to leave this included unless you want to save a very small amount of @@ -183,11 +174,6 @@ ifeq ($(WITH_THREADING),yes) LIB_CFLAGS:=$(LIB_CFLAGS) -DWITH_THREADING endif -ifeq ($(WITH_STRICT_PROTOCOL),yes) - LIB_CFLAGS:=$(LIB_CFLAGS) -DWITH_STRICT_PROTOCOL - BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_STRICT_PROTOCOL -endif - ifeq ($(WITH_BRIDGE),yes) BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_BRIDGE endif diff --git a/lib/read_handle_client.c b/lib/read_handle_client.c index 22f5898d..8bcf5ff7 100644 --- a/lib/read_handle_client.c +++ b/lib/read_handle_client.c @@ -29,11 +29,6 @@ int _mosquitto_handle_connack(struct mosquitto *mosq) int rc; assert(mosq); -#ifdef WITH_STRICT_PROTOCOL - if(mosq->in_packet.remaining_length != 2){ - return MOSQ_ERR_PROTOCOL; - } -#endif _mosquitto_log_printf(mosq, MOSQ_LOG_DEBUG, "Client %s received CONNACK", mosq->id); rc = _mosquitto_read_byte(&mosq->in_packet, &byte); // Reserved byte, not used if(rc) return rc; diff --git a/lib/read_handle_shared.c b/lib/read_handle_shared.c index b368a029..41e26995 100644 --- a/lib/read_handle_shared.c +++ b/lib/read_handle_shared.c @@ -34,11 +34,6 @@ Contributors: int _mosquitto_handle_pingreq(struct mosquitto *mosq) { assert(mosq); -#ifdef WITH_STRICT_PROTOCOL - if(mosq->in_packet.remaining_length != 0){ - return MOSQ_ERR_PROTOCOL; - } -#endif #ifdef WITH_BROKER _mosquitto_log_printf(NULL, MOSQ_LOG_DEBUG, "Received PINGREQ from %s", mosq->id); #else @@ -50,11 +45,6 @@ int _mosquitto_handle_pingreq(struct mosquitto *mosq) int _mosquitto_handle_pingresp(struct mosquitto *mosq) { assert(mosq); -#ifdef WITH_STRICT_PROTOCOL - if(mosq->in_packet.remaining_length != 0){ - return MOSQ_ERR_PROTOCOL; - } -#endif mosq->ping_t = 0; /* No longer waiting for a PINGRESP. */ #ifdef WITH_BROKER _mosquitto_log_printf(NULL, MOSQ_LOG_DEBUG, "Received PINGRESP from %s", mosq->id); @@ -70,11 +60,6 @@ int _mosquitto_handle_pubackcomp(struct mosquitto *mosq, const char *type) int rc; assert(mosq); -#ifdef WITH_STRICT_PROTOCOL - if(mosq->in_packet.remaining_length != 2){ - return MOSQ_ERR_PROTOCOL; - } -#endif rc = _mosquitto_read_uint16(&mosq->in_packet, &mid); if(rc) return rc; #ifdef WITH_BROKER @@ -108,11 +93,6 @@ int _mosquitto_handle_pubrec(struct mosquitto *mosq) int rc; assert(mosq); -#ifdef WITH_STRICT_PROTOCOL - if(mosq->in_packet.remaining_length != 2){ - return MOSQ_ERR_PROTOCOL; - } -#endif rc = _mosquitto_read_uint16(&mosq->in_packet, &mid); if(rc) return rc; #ifdef WITH_BROKER @@ -140,11 +120,6 @@ int _mosquitto_handle_pubrel(struct mosquitto_db *db, struct mosquitto *mosq) int rc; assert(mosq); -#ifdef WITH_STRICT_PROTOCOL - if(mosq->in_packet.remaining_length != 2){ - return MOSQ_ERR_PROTOCOL; - } -#endif if(mosq->protocol == mosq_p_mqtt311){ if((mosq->in_packet.command&0x0F) != 0x02){ return MOSQ_ERR_PROTOCOL; @@ -231,11 +206,6 @@ int _mosquitto_handle_unsuback(struct mosquitto *mosq) int rc; assert(mosq); -#ifdef WITH_STRICT_PROTOCOL - if(mosq->in_packet.remaining_length != 2){ - return MOSQ_ERR_PROTOCOL; - } -#endif #ifdef WITH_BROKER _mosquitto_log_printf(NULL, MOSQ_LOG_DEBUG, "Received UNSUBACK from %s", mosq->id); #else diff --git a/src/read_handle_client.c b/src/read_handle_client.c index 76a1ed28..85c15190 100644 --- a/src/read_handle_client.c +++ b/src/read_handle_client.c @@ -36,11 +36,6 @@ int mqtt3_handle_connack(struct mosquitto_db *db, struct mosquitto *context) if(!context){ return MOSQ_ERR_INVAL; } -#ifdef WITH_STRICT_PROTOCOL - if(context->in_packet.remaining_length != 2){ - return MOSQ_ERR_PROTOCOL; - } -#endif _mosquitto_log_printf(NULL, MOSQ_LOG_DEBUG, "Received CONNACK on connection %s.", context->id); if(_mosquitto_read_byte(&context->in_packet, &byte)) return 1; // Reserved byte, not used if(_mosquitto_read_byte(&context->in_packet, &rc)) return 1; diff --git a/src/read_handle_server.c b/src/read_handle_server.c index 7c8cda4d..e4f96c22 100644 --- a/src/read_handle_server.c +++ b/src/read_handle_server.c @@ -147,11 +147,7 @@ int mqtt3_handle_connect(struct mosquitto_db *db, struct mosquitto *context) } slen = strlen(client_id); -#ifdef WITH_STRICT_PROTOCOL - if(slen > 23 || slen == 0){ -#else if(slen == 0){ -#endif if(context->protocol == mosq_p_mqtt31){ _mosquitto_free(client_id); _mosquitto_send_connack(context, 0, CONNACK_REFUSED_IDENTIFIER_REJECTED); diff --git a/test/broker/01-connect-invalid-id-24.py b/test/broker/01-connect-invalid-id-24.py deleted file mode 100755 index 9ddad4c5..00000000 --- a/test/broker/01-connect-invalid-id-24.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env python - -# Test whether a CONNECT with a too-long client id results in the correct CONNACK packet. - -import subprocess -import socket -import time - -import inspect, os, sys -# From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder -cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],".."))) -if cmd_subfolder not in sys.path: - sys.path.insert(0, cmd_subfolder) - -import mosq_test - -rc = 1 -keepalive = 10 -connect_packet = mosq_test.gen_connect("connect-invalid-id-test-", keepalive=keepalive) -connack_packet = mosq_test.gen_connack(rc=2) - -broker = subprocess.Popen(['../../src/mosquitto', '-p', '1888'], stderr=subprocess.PIPE) - -try: - time.sleep(0.5) - - sock = mosq_test.do_client_connect(connect_packet, connack_packet) - sock.close() - rc = 0 - -finally: - broker.terminate() - broker.wait() - if rc: - (stdo, stde) = broker.communicate() - print(stde) - -exit(rc) - diff --git a/test/broker/Makefile b/test/broker/Makefile index a2b10e9f..e6bf090c 100644 --- a/test/broker/Makefile +++ b/test/broker/Makefile @@ -88,6 +88,3 @@ test : test-compile 01 02 03 04 05 06 07 08 09 10 10 : ./10-listener-mount-point.py -# Tests for with WITH_STRICT_PROTOCOL defined -strict-test : - ./01-connect-invalid-id-24.py