From 79d41e5fa302ba983997b1511bee3525cb31b450 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Thu, 27 Feb 2020 23:04:16 +0000 Subject: [PATCH] 01_FHEMWEB.pm: Collect some statistics & limit header size git-svn-id: https://svn.fhem.de/fhem/trunk@21298 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/01_FHEMWEB.pm | 12 ++++++++++++ fhem/FHEM/TcpServerUtils.pm | 2 ++ 2 files changed, 14 insertions(+) diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm index 6eedf2fce..de6f82a7d 100644 --- a/fhem/FHEM/01_FHEMWEB.pm +++ b/fhem/FHEM/01_FHEMWEB.pm @@ -305,6 +305,8 @@ FW_Define($$) } }, $hash, 0); } + $hash->{BYTES_READ} = 0; + $hash->{BYTES_WRITTEN} = 0; return $ret; } @@ -362,11 +364,15 @@ FW_Read($$) (defined($ret) ? 'EOF' : $!); return; } + my $sh = $defs{$FW_wname}; + $sh->{BYTES_READ} += length($buf); + $hash->{BUF} .= $buf; if($hash->{SSL} && $c->can('pending')) { while($c->pending()) { sysread($c, $buf, 1024); $hash->{BUF} .= $buf; + $sh->{BYTES_READ} += length($buf); } } } @@ -421,6 +427,10 @@ FW_Read($$) if(!$hash->{HDR}) { + if(length($hash->{BUF}) > 1000000) { + Log3 $FW_wname, 2, "Too much header, terminating $hash->{PEER}"; + return TcpServer_Close($hash, 1); + } return if($hash->{BUF} !~ m/^(.*?)(\n\n|\r\n\r\n)(.*)$/s); $hash->{HDR} = $1; $hash->{BUF} = $3; @@ -429,6 +439,7 @@ FW_Read($$) } } + Log3 $FW_wname, 5, $hash->{HDR}; my $POSTdata = ""; if($hash->{CONTENT_LENGTH}) { return if(length($hash->{BUF})<$hash->{CONTENT_LENGTH}); @@ -714,6 +725,7 @@ FW_addToWritebuffer($$@) } } } + $defs{$hash->{SNAME}}{BYTES_WRITTEN} += length($txt); return addToWritebuffer($hash, $txt, $callback, $nolimit); } diff --git a/fhem/FHEM/TcpServerUtils.pm b/fhem/FHEM/TcpServerUtils.pm index d2e967b3d..88718283e 100644 --- a/fhem/FHEM/TcpServerUtils.pm +++ b/fhem/FHEM/TcpServerUtils.pm @@ -334,6 +334,8 @@ TcpServer_WriteBlocking($$) if( defined $ret ){ $off += $ret; + my $sh = $defs{$hash->{SNAME}}; + $sh->{BYTES_WRITTEN} += $ret if(defined($sh->{BYTES_WRITTEN})); } elsif( $! == EWOULDBLOCK ){ $hash->{wantRead} = 1