CC: | cpan [...] iotti.biz |
Subject: | Warnings in Net::Server::Proto::SSLEAY |
W wrote Paul Seamons about this, but had no answer. Let's try here.
I am using Net::Server::Proto::SSLEAY (from Net::Server 2.007 in CnetOS6; perl is 5.10) in a small perl web server based on HTTP::Server::Simple::CGI::PreFork, which in turn extends HTTP::Server::Simple. I am getting really lots of warnings like this in the logs (one warning for every octet received):
Use of uninitialized value $_[1] in substr at /usr/share/perl5/vendor_perl/Net/Server/Proto/SSLEAY.pm line 313, <$read> line ...
Line 313 is the line with substr in the read sub:
sub read {
my ($client, $buf, $size, $offset) = @_;
my ($ok, $read) = $client->read_until($size, undef, 1);
substr($_[1], $offset || 0, defined($buf) ? length($buf) : 0, $read);
return length $read;
}
The read sub is being called with a undef buffer by the HTTP::Server::Simple module, with sysread( STDIN, my $buff, 1 ). Using an undef buffer seems reasonable, since we have to read, so the buffer has to be written by read.
The following patch simply eliminated my warnings. I would like to ask if it could be safe and in case if it (or another correction) could be included in a future release
--- /usr/share/perl5/vendor_perl/Net/Server/Proto/SSLEAY.pm.orig 2016-09-25 09:03:39.385323059 +0200
+++ /usr/share/perl5/vendor_perl/Net/Server/Proto/SSLEAY.pm 2016-09-25 09:04:35.233305406 +0200
@@ -306,6 +306,7 @@
sub read {
my ($client, $buf, $size, $offset) = @_;
my ($ok, $read) = $client->read_until($size, undef, 1);
+ defined($_[1]) or $_[1] = '';
substr($_[1], $offset || 0, defined($buf) ? length($buf) : 0, $read);
return length $read;
}
Thank you, best regards
Luigi Iotti