Inspect/L7/HTTP/WebSocket.pm

filter: Statementstmt 72.6% 149 / 205 Branchbran 64.3% 94 / 146 Conditioncond 46.3% 25 / 54 MC/DCmcdc 19.3% 6 / 31 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 1 totaltotal 63.5% 284 / 447 CC 96 SCAR 56.0
CC
96
Cov
66%
__ANON__
356.7
upgrade_websocket
28.2
unmask
4.0
CRAP 269.5
« Inspect/L7/HTTP.pm ↑ Summary Inspect/L7/HTTP/Request/InspectChain.pm »
1 ############################################################################
2 # WebSocket support
3 ############################################################################
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 package Net::Inspect::L7::HTTP::WebSocket;
8 1 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Digest::SHA 'sha1_base64';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub upgrade_websocket {
13 1 ▶ my ($self,$conn,$req,$rsp) = @_;
Subroutine upgrade_websocket: called CC=16 SCAR=33.4
Pod undocumented
14  
15 # Websocket: RFC6455, Sec.4.1 Page 16ff
16 1 ▶ my $wskey = $req->{fields}{'sec-websocket-key'} || [];
Condition50%1/2
$req->{'fields'}{'sec-websocket-key'} || []
l!l
10
MC/DC0%0/1
$req->{'fields'}{'sec-websocket-key'} || []
$req->{'fields'}{'sec-websocket-key'}
Truth table50%1/2
A
A= $req->{'fields'}{'sec-websocket-key'}
Aresult
11
00
17 1 ▶ if (@$wskey > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$wskey > 1) 0 1 1
18 0 my %x;
19 0 ▶ $wskey = [ map { $x{$_}++ ? ():($_) } @$wskey ];
Branch: 1 branch
BranchTrueFalseTotal
$x{$_}++ ? : 0 0 0
20 }
21  
22 # Check request
23 1 ▶ die "no sec-websocket-key given in request" if ! @$wskey;
Branch: 1 branch
BranchTrueFalseTotal
unless @$wskey 0 1 1
24 1 ▶ die "multiple sec-websocket-key given in request" if @$wskey > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$wskey > 1 0 1 1
25 die "method must be GET but is $req->{method}"
26 1 ▶ if $req->{method} ne 'GET';
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"method"} ne "GET" 0 1 1
27 1 my $v = $req->{fields}{'sec-websocket-version'};
28 1 ▶ die "no sec-websocket-version field in request" if !$v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 0 1 1
29 die "sec-websocket-version must be 13 not '@$v'"
30 1 ▶ if grep { $_ ne '13' } @$v;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ ne 13;} @$v 0 1 1
31  
32 # Check response
33 1 my $wsa = $rsp->{fields}{'sec-websocket-accept'};
34 1 ▶ if (@$wsa > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$wsa > 1) 0 1 1
35 0 my %x;
36 0 ▶ $wsa = [ map { $x{$_}++ ? ():($_) } @$wsa ];
Branch: 1 branch
BranchTrueFalseTotal
$x{$_}++ ? : 0 0 0
37 }
38 1 ▶ die "no sec-websocket-accept given in response" if ! @$wsa;
Branch: 1 branch
BranchTrueFalseTotal
unless @$wsa 0 1 1
39 1 ▶ die "multiple sec-websocket-accept given in response" if @$wsa > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$wsa > 1 0 1 1
40  
41 # Check that sec-websocket-accept in response matches sec-websocket-key.
42 # Beware its magic! see RFC6455 page 7.
43 # sha1_base64 does no padding, so we need to add a single '=' (pad to 4*7
44 # byte) at the end for comparison.
45 1 ▶ if ( @$wsa != 1 or $wsa->[0] ne sha1_base64(
Branch: 1 branch
BranchTrueFalseTotal
if (@$wsa != 1 or $wsa->[0] ne &sha1_base64($wskey->[0] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11') . '=') 0 1 1
Condition33%1/3
@$wsa != 1 or $wsa->[0] ne &sha1_base64($wskey->[0] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11') . '='
l!l&&r!l&&!r
001
MC/DC0%0/2
@$wsa != 1 or $wsa->[0] ne &sha1_base64($wskey->[0] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11') . '='
@$wsa != 1 $wsa->[0] ne &sha1_base64($wskey->[0] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11') . '='
Truth table33%1/3
A or B
A= @$wsa != 1B= $wsa->[0] ne &sha1_base64($wskey->[0] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11') . '='
ABresult
1X1
011
000
46 $wskey->[0].'258EAFA5-E914-47DA-95CA-C5AB0DC85B11').'=') {
47 0 die "sec-websocket-accept does not match sec-websocket-key";
48 }
49  
50  
51 1 my @sub;
52 1 weaken($self);
53 1 for my $dir (0,1) {
54 2 my $dir = $dir; # old $dir is only alias
55 2 my $rbuf = '';
56  
57 # If $clen is defined we are inside a frame ($current_frame).
58 # If $clen is not defined all other variables here do not matter.
59 # Since control messages might be in-between fragmented data messages we
60 # need to keep this information for an open data message.
61 2 my ($clen,$clenhi,$current_frame,$data_frame,$ctl_frame,$got_close);
62  
63 $sub[$dir] = sub {
64 18 ▶ my ($data,$eof,$time) = @_;
Subroutine __ANON__: called CC=78 SCAR=58.8
65 18 my $err;
66  
67 # Handle data gaps. These are only allowed inside data frames.
68 ############################################################
69 18 ▶ if (ref($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data) 5 13 18
70 5 ▶ croak "unknown type $data->[0]" if $data->[0] ne 'gap';
Branch: 1 branch
BranchTrueFalseTotal
if $data->[0] ne "gap" 0 5 5
71 5 my $gap = $data->[1];
72 5 ▶ if (!defined $clen) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $clen) 0 5 5
73 0 $err = "gap outside websocket frame";
74 0 goto bad;
75 }
76 5 ▶ if (!$data_frame || $current_frame != $data_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $data_frame or $current_frame != $data_frame) 0 5 5
Condition33%1/3
not $data_frame or $current_frame != $data_frame
l!l&&r!l&&!r
005
MC/DC0%0/2
not $data_frame or $current_frame != $data_frame
not $data_frame $current_frame != $data_frame
Truth table33%1/3
not(A) or B
A= not $data_frameB= $current_frame != $data_frame
ABresult
1X1
011
000
77 0 $err = "gap inside control frame";
78 0 goto bad;
79 }
80 5 my $eom = 0; # end of message on end-of-frame + FIN frame
81 5 ▶ while ($gap>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gap > 0) 5 5 10
82 5 ▶ if ($clen == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($clen == 0) { } 0 5 5
elsif ($gap > $clen) { } 0 5 5
83 0 ▶ if (!$clenhi) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($clenhi) 0 0 0
84 0 $err = "gap larger than frame size";
85 0 goto bad;
86 }
87 0 $clenhi--;
88 0 $clen = 0xffffffff;
89 0 $gap--;
90 $current_frame->{mask_offset}
91 0 ▶ = (($current_frame->{mask_offset}||0) + 1) % 4;
Condition0%0/2
$current_frame->{'mask_offset'} || 0
l!l
00
MC/DC0%0/1
$current_frame->{'mask_offset'} || 0
$current_frame->{'mask_offset'}
Truth table0%0/2
A
A= $current_frame->{'mask_offset'}
Aresult
11
00
92  
93 } elsif ($gap > $clen) {
94 0 $gap -= $clen;
95 $current_frame->{mask_offset}
96 0 ▶ = (($current_frame->{mask_offset}||0) + $clen) % 4;
Condition0%0/2
$current_frame->{'mask_offset'} || 0
l!l
00
MC/DC0%0/1
$current_frame->{'mask_offset'} || 0
$current_frame->{'mask_offset'}
Truth table0%0/2
A
A= $current_frame->{'mask_offset'}
Aresult
11
00
97 0 $clen = 0;
98 } else { # $gap <= $clen
99 5 $clen -= $gap;
100 $current_frame->{mask_offset}
101 5 ▶ = (($current_frame->{mask_offset}||0) + $gap) % 4;
Condition100%2/2
$current_frame->{'mask_offset'} || 0
l!l
41
MC/DC100%1/1
$current_frame->{'mask_offset'} || 0
$current_frame->{'mask_offset'}
Truth table100%2/2
A
A= $current_frame->{'mask_offset'}
Aresult
11
00
102 5 $gap = 0;
103 }
104 }
105 5 ▶ if (!$clen && !$clenhi) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($clen or $clenhi) 0 5 5
Condition33%1/3
$clen or $clenhi
l!l&&r!l&&!r
500
MC/DC0%0/2
$clen or $clenhi
$clen $clenhi
Truth table33%1/3
A or B
A= $clenB= $clenhi
ABresult
1X1
011
000
106 # frame done
107 0 ▶ $eom = $data_frame->{fin} ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
$data_frame->{'fin'} ? : 0 0 0
108 0 $clen = undef;
109 }
110  
111 5 ▶ if (defined $clen) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $clen) { } 5 0 5
112 5 $data_frame->{bytes_left} = [$clenhi,$clen];
113 } else {
114 0 delete $data_frame->{bytes_left};
115 }
116 5 $self->in_wsdata($dir,$data,$eom,$time,$data_frame);
117 5 ▶ if ($eom) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eom) { } 0 5 5
118 0 $data_frame = $current_frame = undef;
119 0 $conn->set_gap_diff($dir,undef);
120 } else {
121 5 delete $data_frame->{init};
122 5 delete $data_frame->{header};
123 }
124 5 return;
125 }
126  
127 13 $rbuf .= $data;
128  
129 PARSE_DATA:
130  
131 # data for existing frame
132 ############################################################
133 21 ▶ if (defined $clen) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $clen) 10 11 21
134 10 my $size = length($rbuf);
135 10 ▶ if (!$size and $clen || $clenhi and $eof) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $size and $clen || $clenhi and $eof) 0 10 10
Condition55%5/9
not $size and $clen || $clenhi and $eof
!ll&&!rl&&r
910
not $size and $clen || $clenhi
!ll&&!rl&&r
901
$clen or $clenhi
l!l&&r!l&&!r
100
MC/DC0%0/4
not $size and $clen || $clenhi and $eof
not $size $clen $clenhi $eof
Truth table33%2/6
not(A) and B or C and D
A= not $sizeB= $clenC= $clenhiD= $eof
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
136 0 $err = "eof inside websocket frame";
137 0 goto bad;
138 }
139 10 my $fwd = '';
140 10 my $eom = 0;
141 10 ▶ while ($size>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > 0) 9 10 19
142 9 ▶ if ($clen == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($clen == 0) { } 0 9 9
elsif ($size > $clen) { } 0 9 9
143 0 ▶ last if !$clenhi;
Branch: 1 branch
BranchTrueFalseTotal
unless $clenhi 0 0 0
144 0 $clenhi--;
145 0 $clen = 0xffffffff;
146 0 $size--;
147 0 $fwd .= substr($rbuf,0,1,'');
148 } elsif ($size > $clen) {
149 0 $size -= $clen;
150 0 $fwd .= substr($rbuf,0,$clen,'');
151 0 $clen = 0;
152 } else { # $size < $clen
153 9 $clen -= $size;
154 9 $size = 0;
155 9 $fwd .= $rbuf;
156 9 $rbuf = '';
157 }
158 }
159 10 ▶ if (!$clen && !$clenhi) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($clen or $clenhi) 8 2 10
Condition66%2/3
$clen or $clenhi
l!l&&r!l&&!r
208
MC/DC50%1/2
$clen or $clenhi
$clen $clenhi
Truth table66%2/3
A or B
A= $clenB= $clenhi
ABresult
1X1
011
000
160 # frame done
161 8 ▶ $eom = $current_frame->{fin} ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
$current_frame->{'fin'} ? : 2 6 8
162 8 $clen = undef;
163 }
164 10 ▶ if ($data_frame && $current_frame == $data_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_frame and $current_frame == $data_frame) { } 6 4 10
Condition100%3/3
$data_frame and $current_frame == $data_frame
!ll&&!rl&&r
226
MC/DC100%2/2
$data_frame and $current_frame == $data_frame
$data_frame $current_frame == $data_frame
Truth table100%3/3
A and B
A= $data_frameB= $current_frame == $data_frame
ABresult
0X0
100
111
165 6 ▶ if (defined $clen) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $clen) { } 2 4 6
166 2 $data_frame->{bytes_left} = [$clenhi,$clen];
167 } else {
168 4 delete $data_frame->{bytes_left};
169 }
170 6 $self->in_wsdata($dir,$fwd,$eom,$time,$data_frame);
171 6 ▶ if ($eom) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eom) { } 2 4 6
172 2 $data_frame = undef;
173 } else {
174 4 delete $data_frame->{init};
175 4 delete $data_frame->{header};
176 $current_frame->{mask_offset}
177 4 ▶ = (($current_frame->{mask_offset}||0) + length($fwd)) % 4
Branch: 1 branch
BranchTrueFalseTotal
if defined $clen 2 2 4
Condition50%1/2
$current_frame->{'mask_offset'} || 0
l!l
02
MC/DC0%0/1
$current_frame->{'mask_offset'} || 0
$current_frame->{'mask_offset'}
Truth table50%1/2
A
A= $current_frame->{'mask_offset'}
Aresult
11
00
178 if defined $clen;
179 }
180 } else {
181 # Control frames are read in full and we make sure about
182 # this when reading the header already.
183 4 ▶ die "expected to read full control frame" if defined $clen;
Branch: 1 branch
BranchTrueFalseTotal
if defined $clen 0 4 4
184  
185 4 ▶ if ($current_frame->{opcode} == 0x8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_frame->{"opcode"} == 8) 2 2 4
186 # extract status + reason for close
187 2 ▶ if ($fwd eq '') {
Branch: 2 branches
BranchTrueFalseTotal
if ($fwd eq '') { } 0 2 2
elsif (length $fwd < 2) { } 0 2 2
188 0 $current_frame->{status} = 1005; # RFC6455, 7.1.5
189 } elsif (length($fwd) < 2) {
190 # if payload it must be at least 2 byte for status
191 0 $err = "invalid length for close control frame";
192 0 goto bad;
193 } else {
194 ($current_frame->{status},$current_frame->{reason})
195 2 = unpack("na*",$current_frame->unmask($fwd));
196 }
197 }
198 4 $self->in_wsctl($dir,$fwd,$time,$current_frame);
199 }
200 10 ▶ goto done if !$size;
Branch: 1 branch
BranchTrueFalseTotal
unless $size 10 0 10
201 0 goto PARSE_DATA;
202 }
203  
204 # start of new frame: read frame header
205 ############################################################
206 11 ▶ goto done if $eof;
Branch: 1 branch
BranchTrueFalseTotal
if $eof 2 9 11
207 9 ▶ goto hdr_need_more if length($rbuf)<2;
Branch: 1 branch
BranchTrueFalseTotal
if length $rbuf < 2 0 9 9
208  
209 9 (my $flags,$clen) = unpack("CC",$rbuf);
210 9 my $mask = $clen & 0x80;
211 9 $clen &= 0x7f;
212 9 $clenhi = 0;
213 9 my $off = 2;
214  
215 9 ▶ if ($clen == 126) {
Branch: 2 branches
BranchTrueFalseTotal
if ($clen == 126) { } 1 8 9
elsif ($clen == 127) { } 2 6 8
216 1 ▶ goto hdr_need_more if length($rbuf)<4;
Branch: 1 branch
BranchTrueFalseTotal
if length $rbuf < 4 0 1 1
217 1 ($clen) = unpack("xxn",$rbuf);
218 1 ▶ goto bad_length if $clen<126;
Branch: 1 branch
BranchTrueFalseTotal
if $clen < 126 0 1 1
219 1 $off = 4;
220 } elsif ($clen == 127) {
221 2 ▶ goto hdr_need_more if length($rbuf)<10;
Branch: 1 branch
BranchTrueFalseTotal
if length $rbuf < 10 0 2 2
222 2 ($clenhi,$clen) = unpack("xxNN",$rbuf);
223 2 ▶ goto bad_length if !$clenhi && $clen<2**16;
Branch: 1 branch
BranchTrueFalseTotal
if not $clenhi and $clen < 65536 0 2 2
Condition33%1/3
not $clenhi and $clen < 65536
!ll&&!rl&&r
020
MC/DC0%0/2
not $clenhi and $clen < 65536
not $clenhi $clen < 65536
Truth table33%1/3
not(A) and B
A= not $clenhiB= $clen < 65536
ABresult
0X0
100
111
224 2 $off = 10;
225 }
226 9 ▶ if ($mask) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mask) { } 7 2 9
227 7 ▶ goto hdr_need_more if length($rbuf)<$off+4;
Branch: 1 branch
BranchTrueFalseTotal
if length $rbuf < $off + 4 1 6 7
228 6 ($mask) = unpack("x${off}a4",$rbuf);
229 6 $off+=4;
230 } else {
231 2 $mask = undef;
232 }
233  
234 8 my $opcode = $flags & 0b00001111;
235 8 my $fin = $flags & 0b10000000;
236 8 ▶ goto reserved_flag if $flags & 0b01110000;
Branch: 1 branch
BranchTrueFalseTotal
if $flags & 112 0 8 8
237  
238 8 ▶ if ($opcode >= 0x8) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opcode >= 8) { } 4 4 8
elsif ($opcode > 0) { } 2 2 4
239 # control frame
240 4 ▶ goto reserved_opcode if $opcode >= 0xb;
Branch: 1 branch
BranchTrueFalseTotal
if $opcode >= 11 0 4 4
241 4 ▶ if (!$fin) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fin) 0 4 4
242 0 $err = "fragmented control frames are forbidden";
243 0 goto bad;
244 }
245 4 ▶ if ($clenhi || $clen>125) {
Branch: 1 branch
BranchTrueFalseTotal
if ($clenhi or $clen > 125) 0 4 4
Condition33%1/3
$clenhi or $clen > 125
l!l&&r!l&&!r
004
MC/DC0%0/2
$clenhi or $clen > 125
$clenhi $clen > 125
Truth table33%1/3
A or B
A= $clenhiB= $clen > 125
ABresult
1X1
011
000
246 0 $err = "control frames should be <= 125 bytes";
247 0 goto bad;
248 }
249 # We like to forward control frames as a single entity, so make
250 # sure we get the whole (small) frame at once.
251 4 ▶ goto hdr_need_more if $off+$clen > length($rbuf);
Branch: 1 branch
BranchTrueFalseTotal
if $off + $clen > length $rbuf 0 4 4
252  
253 4 ▶ $current_frame = $ctl_frame
Condition66%2/3
$ctl_frame ||= "Net::Inspect::L7::HTTP::WebSocket::_WSFrame"->new
l!l&&r!l&&!r
220
MC/DC0%0/2
$ctl_frame ||= "Net::Inspect::L7::HTTP::WebSocket::_WSFrame"->new
$ctl_frame "Net::Inspect::L7::HTTP::WebSocket::_WSFrame"->new
Truth table66%2/3
A ||= B
A= $ctl_frameB= "Net::Inspect::L7::HTTP::WebSocket::_WSFrame"->new
ABresult
1X1
011
000
254 ||= Net::Inspect::L7::HTTP::WebSocket::_WSFrame->new;
255 4 ▶ %$current_frame = (
Branch: 1 branch
BranchTrueFalseTotal
defined $mask ? : 3 1 4
256 opcode => $opcode,
257 defined($mask) ? ( mask => $mask ):()
258 );
259 4 ▶ $got_close = 1 if $opcode == 0x8;
Branch: 1 branch
BranchTrueFalseTotal
if $opcode == 8 2 2 4
260  
261 } elsif ($opcode>0) {
262 # data frame, but no continuation
263 2 ▶ goto reserved_opcode if $opcode >= 0x3;
Branch: 1 branch
BranchTrueFalseTotal
if $opcode >= 3 0 2 2
264 2 ▶ if ($got_close) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got_close) 0 2 2
265 0 $err = "data frame after close";
266 0 goto bad;
267 }
268 2 ▶ if ($data_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_frame) 0 2 2
269 0 $err = "new data message before end of previous message";
270 0 goto bad;
271 }
272 2 $current_frame = $data_frame
273 = Net::Inspect::L7::HTTP::WebSocket::_WSFrame->new;
274 2 ▶ %$current_frame = (
Branch: 2 branches
BranchTrueFalseTotal
$fin ? : 1 1 2
defined $mask ? : 1 1 2
275 opcode => $opcode,
276 $fin ? ( fin => 1 ):(),
277 init => 1, # initial data
278 defined($mask) ? ( mask => $mask ):()
279 );
280  
281 } else {
282 # continuation frame
283 2 ▶ if (!$data_frame) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data_frame) 0 2 2
284 0 $err = "continuation frame without previous data frame";
285 0 goto bad;
286 }
287 2 $current_frame = $data_frame;
288 %$current_frame = (
289 opcode => $data_frame->{opcode},
290 2 ▶ $fin ? ( fin => 1 ):(),
Branch: 2 branches
BranchTrueFalseTotal
$fin ? : 1 1 2
defined $mask ? : 2 0 2
291 defined($mask) ? ( mask => $mask ):()
292 );
293 }
294  
295 # done with frame header
296 8 $current_frame->{header} = substr($rbuf,0,$off,'');
297 8 goto PARSE_DATA;
298  
299 # Done
300 ############################################################
301  
302 1 hdr_need_more:
303 $clen = undef; # re-read from start if frame next time
304 1 return;
305  
306 done:
307 12 ▶ if ($eof) {
Branch: 2 branches
BranchTrueFalseTotal
if ($eof) { } 2 10 12
elsif (defined $clen) { } 2 8 10
308 # forward eof as special wsctl with no frame
309 # FIXME: complain if we have eof but the current frame is not
310 # done yet.
311 2 $self->in_wsctl($dir,'',$time);
312 } elsif (defined $clen) {
313 # We have at least the header of a data frame (control frames
314 # are read as a single entity) and might need more data
315 # (clen>0). Set gap_diff.
316 2 ▶ $clen>0 and $conn->set_gap_diff($dir,
Branch: 2 branches
BranchTrueFalseTotal
$clen > 0 and $conn->set_gap_diff($dir, !$clenhi ? $clen : ($clenhi << 32) + $clen) 2 0 2
!$clenhi ? : 2 0 2
317 ! $clenhi ? $clen : # len <=32 bit
318 1 << 32 == 1 ? 0xffffffff : # maxint on 32-bit platform
319 ($clenhi << 32) + $clen # full 64 bit
320 );
321 }
322 12 return;
323  
324 0 ▶ bad_length:
Condition0%0/2
$err ||= "non-minimal length representation in websocket frame"
l!l
00
MC/DC0%0/1
$err ||= "non-minimal length representation in websocket frame"
$err
Truth table0%0/2
A
A= $err
Aresult
11
00
325 $err ||= "non-minimal length representation in websocket frame";
326 0 ▶ reserved_flag:
Condition0%0/2
$err ||= "extensions using reserved flags are not supported"
l!l
00
MC/DC0%0/1
$err ||= "extensions using reserved flags are not supported"
$err
Truth table0%0/2
A
A= $err
Aresult
11
00
327 $err ||= "extensions using reserved flags are not supported";
328 0 ▶ reserved_opcode:
Condition0%0/2
$err ||= "no support for opcode $opcode"
l!l
00
MC/DC0%0/1
$err ||= "no support for opcode $opcode"
$err
Truth table0%0/2
A
A= $err
Aresult
11
00
329 $err ||= "no support for opcode $opcode";
330  
331 bad:
332 0 $conn->{error} = 1;
333 0 $self->fatal($err,$dir,$time);
334 0 return;
335 2 };
336 }
337  
338 return sub {
339 18 ▶ my $dir = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
340 18 goto &{$sub[$dir]};
341 }
342 1 }
343  
344 {
345 package Net::Inspect::L7::HTTP::WebSocket::_WSFrame;
346 4 ▶ sub new { bless {}, shift };
Subroutine new: called CC=1 SCAR=0.0
347 sub unmask {
348 11 ▶ my ($self,$data) = @_;
Subroutine unmask: called CC=4 SCAR=13.9
349 11 ▶ return $data if $data eq '' or ! $self->{mask};
Branch: 1 branch
BranchTrueFalseTotal
if $data eq "" or not $self->{"mask"} 3 8 11
Condition66%2/3
$data eq "" or not $self->{"mask"}
l!l&&r!l&&!r
038
MC/DC50%1/2
$data eq "" or not $self->{"mask"}
$data eq "" not $self->{"mask"}
Truth table66%2/3
A or not(B)
A= $data eq ""B= not $self->{"mask"}
ABresult
1X1
011
000
350 8 my $l = length($data);
351 8 ▶ $data ^= substr($self->{mask} x int($l/4+2),$self->{mask_offset}||0,$l);
Condition100%2/2
$self->{'mask_offset'} || 0
l!l
17
MC/DC100%1/1
$self->{'mask_offset'} || 0
$self->{'mask_offset'}
Truth table100%2/2
A
A= $self->{'mask_offset'}
Aresult
11
00
352 8 return $data;
353 };
354 }
355  
356 1 1;
357  
358 __END__
« Inspect/L7/HTTP.pm ↑ Summary Inspect/L7/HTTP/Request/InspectChain.pm »