Fix CONNECT check for reserved=0, as per MQTT v3.1.1 check MQTT-3.1.2-3.

pull/459/head
Roger A. Light 8 years ago
parent 94978ac89b
commit 96db6d6644

@ -13,6 +13,7 @@ Broker:
- Fix problems with large retained messages over websockets. Closes #427.
- Set persistence file to only be readable by owner, except on Windows. Closes
#468.
- Fix CONNECT check for reserved=0, as per MQTT v3.1.1 check MQTT-3.1.2-3.
Clients:
- Don't use / in auto-generated client ids.

@ -171,6 +171,13 @@ int mqtt3_handle_connect(struct mosquitto_db *db, struct mosquitto *context)
rc = 1;
goto handle_connect_error;
}
if(context->protocol == mosq_p_mqtt311){
if((connect_flags & 0x01) != 0x00){
rc = MOSQ_ERR_PROTOCOL;
goto handle_connect_error;
}
}
clean_session = (connect_flags & 0x02) >> 1;
will = connect_flags & 0x04;
will_qos = (connect_flags & 0x18) >> 3;

@ -0,0 +1,33 @@
#!/usr/bin/env python
# Test whether a CONNECT with reserved set to 1 results in a disconnect. MQTT-3.1.2-3
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-test", keepalive=keepalive, connect_reserved=True, proto_ver=4)
cmd = ['../../src/mosquitto', '-p', '1888']
broker = mosq_test.start_broker(filename=os.path.basename(__file__), cmd=cmd)
try:
sock = mosq_test.do_client_connect(connect_packet, "")
sock.close()
rc = 0
finally:
broker.terminate()
broker.wait()
if rc:
(stdo, stde) = broker.communicate()
print(stde)
exit(rc)

@ -20,6 +20,7 @@ test : test-compile 01 02 03 04 05 06 07 08 09 10
./01-connect-invalid-id-0.py
./01-connect-invalid-id-0-311.py
./01-connect-invalid-id-missing.py
./01-connect-invalid-reserved.py
./01-connect-anon-denied.py
./01-connect-uname-no-password-denied.py
./01-connect-uname-password-denied.py

@ -91,6 +91,19 @@ def remaining_length(packet):
return (packet, rl)
def to_hex_string(packet):
if len(packet) == 0:
return ""
s = ""
while len(packet) > 0:
packet0 = struct.unpack("!B", packet[0])
s = s+hex(packet0[0]) + " "
packet = packet[1:]
return s
def to_string(packet):
if len(packet) == 0:
return ""
@ -150,6 +163,9 @@ def to_string(packet):
(password, packet) = struct.unpack(pack_format, packet)
s = s+", password="+password
if flags&1:
s = s+", reserved=1"
return s
elif cmd == 0x20:
# CONNACK
@ -250,7 +266,7 @@ def to_string(packet):
# Reserved
return "0xF0"
def gen_connect(client_id, clean_session=True, keepalive=60, username=None, password=None, will_topic=None, will_qos=0, will_retain=False, will_payload="", proto_ver=3):
def gen_connect(client_id, clean_session=True, keepalive=60, username=None, password=None, will_topic=None, will_qos=0, will_retain=False, will_payload="", proto_ver=3, connect_reserved=False):
if (proto_ver&0x7F) == 3 or proto_ver == 0:
remaining_length = 12
elif (proto_ver&0x7F) == 4:
@ -262,6 +278,10 @@ def gen_connect(client_id, clean_session=True, keepalive=60, username=None, pass
remaining_length = remaining_length + 2+len(client_id)
connect_flags = 0
if connect_reserved:
connect_flags = connect_flags | 0x01
if clean_session:
connect_flags = connect_flags | 0x02

Loading…
Cancel
Save