From 1e210ec4adeb321760d68d448596d7f4c0f18801 Mon Sep 17 00:00:00 2001 From: Sergey Kandaurov Date: Wed, 3 May 2017 13:36:40 +0300 Subject: [PATCH] Tests: avoid illegal dereference on errors in h2_headers.t. --- h2_headers.t | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/h2_headers.t b/h2_headers.t index 46439fe4..32dc2718 100644 --- a/h2_headers.t +++ b/h2_headers.t @@ -26,7 +26,7 @@ use Test::Nginx::HTTP2; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite/)->plan(92) +my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite/)->plan(93) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -606,13 +606,14 @@ $sid = $s->new_stream({ path => '/continuation?h=' . 'x' x 2**13 }); $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]); my @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; -is(@{$data[-1]->{headers}{'x-longheader'}}, 3, +my $data = $data[-1]; +is(@{$data->{headers}{'x-longheader'}}, 3, 'response CONTINUATION - headers'); -is($data[-1]->{headers}{'x-longheader'}[0], 'x' x 2**13, +is($data->{headers}{'x-longheader'}[0], 'x' x 2**13, 'response CONTINUATION - header 1'); -is($data[-1]->{headers}{'x-longheader'}[1], 'x' x 2**13, +is($data->{headers}{'x-longheader'}[1], 'x' x 2**13, 'response CONTINUATION - header 2'); -is($data[-1]->{headers}{'x-longheader'}[2], 'x' x 2**13, +is($data->{headers}{'x-longheader'}[2], 'x' x 2**13, 'response CONTINUATION - header 3'); @data = sort { $a <=> $b } map { $_->{length} } @data; cmp_ok($data[-1], '<=', 2**14, 'response CONTINUATION - max frame size'); @@ -624,13 +625,14 @@ $sid = $s->new_stream({ path => '/continuation/204?h=' . 'x' x 2**13 }); $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]); @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; -is(@{$data[-1]->{headers}{'x-longheader'}}, 3, +$data = $data[-1]; +is(@{$data->{headers}{'x-longheader'}}, 3, 'no body CONTINUATION - headers'); -is($data[-1]->{headers}{'x-longheader'}[0], 'x' x 2**13, +is($data->{headers}{'x-longheader'}[0], 'x' x 2**13, 'no body CONTINUATION - header 1'); -is($data[-1]->{headers}{'x-longheader'}[1], 'x' x 2**13, +is($data->{headers}{'x-longheader'}[1], 'x' x 2**13, 'no body CONTINUATION - header 2'); -is($data[-1]->{headers}{'x-longheader'}[2], 'x' x 2**13, +is($data->{headers}{'x-longheader'}[2], 'x' x 2**13, 'no body CONTINUATION - header 3'); @data = sort { $a <=> $b } map { $_->{length} } @data; cmp_ok($data[-1], '<=', 2**14, 'no body CONTINUATION - max frame size'); @@ -674,12 +676,19 @@ $sid = $s->new_stream({ path => '/continuation?h=' . 'x' x 2**15 }); $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]); @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; +ok(@data, 'response header split'); + +SKIP: { +skip 'response header split failed', 2 unless @data; + my ($lengths) = sort { $b <=> $a } map { $_->{length} } @data; cmp_ok($lengths, '<=', 16384, 'response header split - max size'); -is(length join('', @{@$frames[-1]->{headers}->{'x-longheader'}}), 98304, +is(length join('', @{$data[-1]->{headers}->{'x-longheader'}}), 98304, 'response header split - headers'); +} + # max_field_size - header field name $s = Test::Nginx::HTTP2->new(port(8084));