fix(frame): improve some error reasons when parsing invalid packet
This commit is contained in:
parent
aad9b1c27d
commit
6722722522
|
@ -472,8 +472,8 @@ parse_packet(
|
||||||
) ->
|
) ->
|
||||||
{Properties, <<>>} = parse_properties(Rest, ?MQTT_PROTO_V5, StrictMode),
|
{Properties, <<>>} = parse_properties(Rest, ?MQTT_PROTO_V5, StrictMode),
|
||||||
#mqtt_packet_auth{reason_code = ReasonCode, properties = Properties};
|
#mqtt_packet_auth{reason_code = ReasonCode, properties = Properties};
|
||||||
parse_packet(_Header, _FrameBin, _Options) ->
|
parse_packet(Header, _FrameBin, _Options) ->
|
||||||
?PARSE_ERR(malformed_packet).
|
?PARSE_ERR(#{hit => malformed_packet, header_type => Header#mqtt_packet_header.type}).
|
||||||
|
|
||||||
parse_will_message(
|
parse_will_message(
|
||||||
Packet = #mqtt_packet_connect{
|
Packet = #mqtt_packet_connect{
|
||||||
|
@ -512,8 +512,16 @@ parse_properties(<<0, Rest/binary>>, ?MQTT_PROTO_V5, _StrictMode) ->
|
||||||
{#{}, Rest};
|
{#{}, Rest};
|
||||||
parse_properties(Bin, ?MQTT_PROTO_V5, StrictMode) ->
|
parse_properties(Bin, ?MQTT_PROTO_V5, StrictMode) ->
|
||||||
{Len, Rest} = parse_variable_byte_integer(Bin),
|
{Len, Rest} = parse_variable_byte_integer(Bin),
|
||||||
<<PropsBin:Len/binary, Rest1/binary>> = Rest,
|
case Rest of
|
||||||
{parse_property(PropsBin, #{}, StrictMode), Rest1}.
|
<<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) ->
|
parse_property(<<>>, Props, _StrictMode) ->
|
||||||
Props;
|
Props;
|
||||||
|
|
|
@ -540,8 +540,17 @@ t_parse_incoming_order(_) ->
|
||||||
|
|
||||||
t_parse_incoming_frame_error(_) ->
|
t_parse_incoming_frame_error(_) ->
|
||||||
{Packets, _St} = ?ws_conn:parse_incoming(<<3, 2, 1, 0>>, [], st()),
|
{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 := _,
|
||||||
|
hit := malformed_packet
|
||||||
|
}}}
|
||||||
|
],
|
||||||
|
Packets
|
||||||
|
).
|
||||||
|
|
||||||
t_handle_incomming_frame_error(_) ->
|
t_handle_incomming_frame_error(_) ->
|
||||||
FrameError = {frame_error, bad_qos},
|
FrameError = {frame_error, bad_qos},
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Improve some error reasons for parsing with invalid packets.
|
Loading…
Reference in New Issue