Skip to content

Commit

Permalink
* FIX [mqtt_parser] caculate CONNECT packet length correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
JaylinYu committed Apr 22, 2023
1 parent 8492a49 commit dae3b1e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/sp/protocol/mqtt/mqtt_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ conn_handler(uint8_t *packet, conn_param *cparam, size_t max)
cparam->pro_name.body =
(char *) copyn_utf8_str(packet, &pos, &len_of_str, max - pos);
cparam->pro_name.len = len_of_str;
rv = (len_of_str < 0 && pos + 4 < max) ? PROTOCOL_ERROR : 0;
// At least 4 bytes left in valid CONNECT
rv = (len_of_str < 0 || pos + 4 > max) ? PROTOCOL_ERROR : 0;
if (strncmp(cparam->pro_name.body, "MQTT", 4) != 0)
rv = PROTOCOL_ERROR;
if (rv != 0)
Expand Down

0 comments on commit dae3b1e

Please sign in to comment.