Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do_httpx2 throws undef warnings on malformed headers. #296

Open
petdance opened this issue Sep 20, 2021 · 0 comments
Open

do_httpx2 throws undef warnings on malformed headers. #296

petdance opened this issue Sep 20, 2021 · 0 comments

Comments

@petdance
Copy link

The function do_httpx2:

sub do_httpx2 {
    my ($page, $response, $headers, $server_cert) = &do_httpx3;
    X509_free($server_cert) if defined $server_cert;
    return ($page, $response, defined $headers ?
        map( { ($h,$v)=/^(\S+)\:\s*(.*)$/; (uc($h),$v); }
        split(/\s?\n/, $headers)
        ) : ()
        );
}

throws undef warnings if the $headers it receives are malformed. If the header doesn't match the
regex in map, $h will be undef and then uc($h) will throw a warning.

Here's a test program that illustrates it:

$ cat foo.pl
use strict;
use warnings;

use Data::Dumper;

my $headers = "foo: bar\n\nfoo\nbaz:\n";
my %hash = map(
    {my ($h,$v)=/^(\S+)\:\s*(.*)$/; (uc($h),$v); }
    split(/\s?\n/, $headers)
);
print Dumper(\%hash);

Running:

$ perl foo.pl
Use of uninitialized value $h in uc at foo.pl line 8.
$VAR1 = {
          'BAZ' => '',
          '' => undef,
          'FOO' => 'bar'
        };

Also, it looks like do_httpsx4 suffers from the same problem, but I haven't tested it.

I get this error 10-80 times/day in our production web server. Counts from September 2021:

01.err:19
02.err:47
03.err:38
04.err:0
05.err:0
06.err:10
07.err:38
08.err:43
09.err:25
10.err:83
11.err:0
12.err:2
13.err:10
14.err:20
15.err:3
16.err:17
17.err:17
18.err:2
19.err:18
20.err:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant