aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Polvorin <[email protected]>2016-10-06 17:12:52 -0300
committerLoïc Hoguin <[email protected]>2016-10-09 00:21:39 +0200
commitb7ae1f55199b8e7057e991874b6cafa065f159b0 (patch)
treeb8754f19ed30840228f96e00986b13f5d74b825c
parent97d840592fb83d774a178d681f73298ba85e5cdc (diff)
downloadcowlib-b7ae1f55199b8e7057e991874b6cafa065f159b0.tar.gz
cowlib-b7ae1f55199b8e7057e991874b6cafa065f159b0.tar.bz2
cowlib-b7ae1f55199b8e7057e991874b6cafa065f159b0.zip
Fix parsing of HTTP/2 PING frames
Fix for cases where the full frame is not received in one go.
-rw-r--r--src/cow_http2.erl11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/cow_http2.erl b/src/cow_http2.erl
index a0d1297..c2dba8b 100644
--- a/src/cow_http2.erl
+++ b/src/cow_http2.erl
@@ -196,7 +196,7 @@ parse(<< 8:24, 6:8, _:7, 0:1, _:1, 0:31, Opaque:64, Rest/bits >>) ->
{ok, {ping, Opaque}, Rest};
parse(<< 8:24, 6:8, _:104, _/bits >>) ->
{connection_error, protocol_error, 'PING frames MUST NOT be associated with a stream. (RFC7540 6.7)'};
-parse(<< _:24, 6:8, _/bits >>) ->
+parse(<< Len:24, 6:8, _/bits >>) when Len =/= 8 ->
{connection_error, frame_size_error, 'PING frames MUST be 8 bytes wide. (RFC7540 6.7)'};
%%
%% GOAWAY frames.
@@ -233,6 +233,15 @@ parse(<< Len:24, 9:8, _:5, FlagEndHeaders:1, _:3, StreamID:31, HeaderBlockFragme
parse(_) ->
more.
+-ifdef(TEST).
+parse_ping_test() ->
+ Ping = ping(1234567890),
+ _ = [more = parse(binary:part(Ping, 0, I)) || I <- lists:seq(1, byte_size(Ping) - 1)],
+ {ok, {ping, 1234567890}, <<>>} = parse(Ping),
+ {ok, {ping, 1234567890}, << 42 >>} = parse(<< Ping/binary, 42 >>),
+ ok.
+-endif.
+
parse_fin(0) -> nofin;
parse_fin(1) -> fin.