Merge pull request #11532 from lafirest/fix/frame_parse
fix(frame): improve some error reasons when parsing invalid packet
This commit is contained in:
commit
8b3a9072f9
|
@ -472,8 +472,8 @@ parse_packet(
|
|||
) ->
|
||||
{Properties, <<>>} = parse_properties(Rest, ?MQTT_PROTO_V5, StrictMode),
|
||||
#mqtt_packet_auth{reason_code = ReasonCode, properties = Properties};
|
||||
parse_packet(_Header, _FrameBin, _Options) ->
|
||||
?PARSE_ERR(malformed_packet).
|
||||
parse_packet(Header, _FrameBin, _Options) ->
|
||||
?PARSE_ERR(#{hint => malformed_packet, header_type => Header#mqtt_packet_header.type}).
|
||||
|
||||
parse_will_message(
|
||||
Packet = #mqtt_packet_connect{
|
||||
|
@ -512,8 +512,16 @@ parse_properties(<<0, Rest/binary>>, ?MQTT_PROTO_V5, _StrictMode) ->
|
|||
{#{}, Rest};
|
||||
parse_properties(Bin, ?MQTT_PROTO_V5, StrictMode) ->
|
||||
{Len, Rest} = parse_variable_byte_integer(Bin),
|
||||
<<PropsBin:Len/binary, Rest1/binary>> = Rest,
|
||||
{parse_property(PropsBin, #{}, StrictMode), Rest1}.
|
||||
case Rest of
|
||||
<<PropsBin:Len/binary, Rest1/binary>> ->
|
||||
{parse_property(PropsBin, #{}, StrictMode), Rest1};
|
||||
_ ->
|
||||
?PARSE_ERR(#{
|
||||
hint => user_property_not_enough_bytes,
|
||||
parsed_key_length => Len,
|
||||
remaining_bytes_length => byte_size(Rest)
|
||||
})
|
||||
end.
|
||||
|
||||
parse_property(<<>>, Props, _StrictMode) ->
|
||||
Props;
|
||||
|
|
|
@ -540,8 +540,17 @@ t_parse_incoming_order(_) ->
|
|||
|
||||
t_parse_incoming_frame_error(_) ->
|
||||
{Packets, _St} = ?ws_conn:parse_incoming(<<3, 2, 1, 0>>, [], st()),
|
||||
FrameError = {frame_error, malformed_packet},
|
||||
[{incoming, FrameError}] = Packets.
|
||||
|
||||
?assertMatch(
|
||||
[
|
||||
{incoming,
|
||||
{frame_error, #{
|
||||
header_type := _,
|
||||
hint := malformed_packet
|
||||
}}}
|
||||
],
|
||||
Packets
|
||||
).
|
||||
|
||||
t_handle_incomming_frame_error(_) ->
|
||||
FrameError = {frame_error, bad_qos},
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Improve some error reasons when parsing invalid packets.
|
Loading…
Reference in New Issue