Crash when reserved flag in CONNECT packet doesn't equal to 0, and remove repeated check for protocol version

This commit is contained in:
周子博 2018-09-04 11:16:15 +08:00
parent fe91484806
commit 842f4fbf13
1 changed files with 3 additions and 5 deletions

View File

@ -120,19 +120,17 @@ wrap(Header, Rest) ->
parse_packet(#mqtt_packet_header{type = ?CONNECT}, FrameBin, _Options) ->
{ProtoName, Rest} = parse_utf8_string(FrameBin),
<<BridgeTag:4, ProtoVer:4, Rest1/binary>> = Rest,
% Note: Crash when reserved flag doesn't equal to 0, there is no strict compliance with the MQTT5.0.
<<UsernameFlag : 1,
PasswordFlag : 1,
WillRetain : 1,
WillQoS : 2,
WillFlag : 1,
CleanStart : 1,
_Reserved : 1,
0 : 0,
KeepAlive : 16/big,
Rest2/binary>> = Rest1,
case protocol_approved(ProtoVer, ProtoName) of
true -> ok;
false -> error(protocol_name_unapproved)
end,
{Properties, Rest3} = parse_properties(Rest2, ProtoVer),
{ClientId, Rest4} = parse_utf8_string(Rest3),
ConnPacket = #mqtt_packet_connect{proto_name = ProtoName,