Fix unused flags in CONNECT command being forced to be 0 in MQTT v3.1

This check is not required until v3.1.1.

Closes #2522. Thanks to garinocyr
This commit is contained in:
Roger A. Light 2022-05-17 17:41:57 +01:00
parent b6b8039914
commit 09ac578459
3 changed files with 13 additions and 3 deletions

View File

@ -7,6 +7,8 @@ Broker:
- Fix bridge `restart_timeout` not being honoured. - Fix bridge `restart_timeout` not being honoured.
- Fix potential memory leaks if a plugin modifies the message in the - Fix potential memory leaks if a plugin modifies the message in the
MOSQ_EVT_MESSAGE event. MOSQ_EVT_MESSAGE event.
- Fix unused flags in CONNECT command being forced to be 0, which is not
required for MQTT v3.1. Closes #2522.
Client library: Client library:
- Fix threads library detection on Windows under cmake. Bumps the minimum - Fix threads library detection on Windows under cmake. Bumps the minimum

View File

@ -458,9 +458,6 @@ int handle__connect(struct mosquitto *context)
rc = MOSQ_ERR_PROTOCOL; rc = MOSQ_ERR_PROTOCOL;
goto handle_connect_error; goto handle_connect_error;
} }
if(context->in_packet.command != CMD_CONNECT){
return MOSQ_ERR_MALFORMED_PACKET;
}
/* Read protocol name as length then bytes rather than with read_string /* Read protocol name as length then bytes rather than with read_string
* because the length is fixed and we can check that. Removes the need * because the length is fixed and we can check that. Removes the need
@ -528,6 +525,9 @@ int handle__connect(struct mosquitto *context)
rc = MOSQ_ERR_PROTOCOL; rc = MOSQ_ERR_PROTOCOL;
goto handle_connect_error; goto handle_connect_error;
} }
if((protocol_version&0x7F) != PROTOCOL_VERSION_v31 && context->in_packet.command != CMD_CONNECT){
return MOSQ_ERR_MALFORMED_PACKET;
}
if(packet__read_byte(&context->in_packet, &connect_flags)){ if(packet__read_byte(&context->in_packet, &connect_flags)){
rc = MOSQ_ERR_PROTOCOL; rc = MOSQ_ERR_PROTOCOL;

View File

@ -3,6 +3,14 @@
"comment": "CONNECT TESTS ARE INCOMPLETE", "comment": "CONNECT TESTS ARE INCOMPLETE",
"group": "v3.1 CONNECT", "group": "v3.1 CONNECT",
"tests": [ "tests": [
{ "name": "10 ok ", "connect":false, "expect_disconnect":false, "msgs":[
{"type":"send", "payload":"10 0F 0006 4D5149736470 03 01 000A 0001 70", "comment":"minimal valid CONNECT"},
{"type":"recv", "payload":"20 02 00 00", "comment": "CONNACK"}
]},
{ "name": "14 ok ", "connect":false, "expect_disconnect":false, "msgs":[
{"type":"send", "payload":"14 0F 0006 4D5149736470 03 01 000A 0001 70", "comment":"CONNECT with QoS=1"},
{"type":"recv", "payload":"20 02 00 00", "comment": "CONNACK"}
]},
{ "name": "10 proto ver 2", "connect":false, "msgs":[ { "name": "10 proto ver 2", "connect":false, "msgs":[
{"type":"send", "payload":"10 0F 0006 4D5149736470 02 00 000A 0001 70", "comment":"CONNECT"}, {"type":"send", "payload":"10 0F 0006 4D5149736470 02 00 000A 0001 70", "comment":"CONNECT"},
{"type":"recv", "payload":"20 02 00 01", "comment": "CONNACK identifier rejected"} {"type":"recv", "payload":"20 02 00 01", "comment": "CONNACK identifier rejected"}