Skip to content

Commit

Permalink
Fix unused flags in CONNECT command being forced to be 0 in MQTT v3.1
Browse files Browse the repository at this point in the history
This check is not required until v3.1.1.

Closes #2522. Thanks to garinocyr
  • Loading branch information
ralight committed May 17, 2022
1 parent b6b8039 commit 09ac578
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -7,6 +7,8 @@ Broker:
- Fix bridge `restart_timeout` not being honoured.
- Fix potential memory leaks if a plugin modifies the message in the
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:
- Fix threads library detection on Windows under cmake. Bumps the minimum
Expand Down
6 changes: 3 additions & 3 deletions src/handle_connect.c
Expand Up @@ -458,9 +458,6 @@ int handle__connect(struct mosquitto *context)
rc = MOSQ_ERR_PROTOCOL;
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
* because the length is fixed and we can check that. Removes the need
Expand Down Expand Up @@ -528,6 +525,9 @@ int handle__connect(struct mosquitto *context)
rc = MOSQ_ERR_PROTOCOL;
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)){
rc = MOSQ_ERR_PROTOCOL;
Expand Down
8 changes: 8 additions & 0 deletions test/broker/data/CONNECT.json
Expand Up @@ -3,6 +3,14 @@
"comment": "CONNECT TESTS ARE INCOMPLETE",
"group": "v3.1 CONNECT",
"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":[
{"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"}
Expand Down

0 comments on commit 09ac578

Please sign in to comment.