From 6c5f781bc58cef0a28ab2dbc7eeb1391df3ba009 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Sat, 8 Nov 2008 02:32:03 +0000 Subject: Fixed bug where extra headers and redirect caused segfault (Dieter Van de Walle - 2089159) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2076 f882894a-f735-0410-b71e-b25c423dba1c --- NEWS | 1 + THANKS.in | 1 + plugins/check_http.c | 4 +++- plugins/tests/check_http.t | 31 +++++++++++++++++++++++++++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 01e8663a..670e4766 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ This file documents the major additions and syntax changes between releases. Fixed segfault in extra-opts under some circumstance when reading multiple sections Fix long options parsing in check_tcp check_icmp now reports min and max round trip time perfdata (Steve Rader) + Fixed bug where additional headers with redirection caused a segfault (Dieter Van de Walle - 2089159) 1.4.13 25th Sept 2008 Fix Debian bug #460097: check_http --max-age broken (Hilko Bengen) diff --git a/THANKS.in b/THANKS.in index b042f9e7..1835e614 100644 --- a/THANKS.in +++ b/THANKS.in @@ -241,3 +241,4 @@ Erik Wasser Tilman Koschnick Olivier 'Babar' Raginel Steve Rader +Dieter Van de Walle diff --git a/plugins/check_http.c b/plugins/check_http.c index df5daf2d..0746741c 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -815,7 +815,9 @@ check_http (void) for ((pos = strtok(http_opt_headers[i], INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER))) asprintf (&buf, "%s%s\r\n", buf, pos); } - free(http_opt_headers); + /* This cannot be free'd here because a redirection will then try to access this and segfault */ + /* Covered in a testcase in tests/check_http.t */ + /* free(http_opt_headers); */ } /* optionally send the authentication info */ diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index d54932e6..c5f90803 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t @@ -28,7 +28,8 @@ if ($pid) { #print "child\n"; my $d = HTTP::Daemon->new( - LocalPort => $port + LocalPort => $port, + LocalAddr => "127.0.0.1", ) || die; print "Please contact me at: url, ">\n"; while (my $c = $d->accept ) { @@ -57,6 +58,12 @@ if ($pid) { $c->send_basic_header; $c->send_crlf; $c->send_response($r->method.":".$r->content); + } elsif ($r->url->path eq "/redirect") { + $c->send_redirect( "/redirect2" ); + } elsif ($r->url->path eq "/redirect2") { + $c->send_basic_header; + $c->send_crlf; + $c->send_response("redirected"); } else { $c->send_error(RC_FORBIDDEN); } @@ -73,7 +80,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { } if (-x "./check_http") { - plan tests => 39; + plan tests => 47; } else { plan skip_all => "No check_http compiled"; } @@ -180,3 +187,23 @@ $result = NPTest->testCmd( $cmd ); is( $result->return_code, 0, $cmd); like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); +$cmd = "$command -u /redirect"; +$result = NPTest->testCmd( $cmd ); +is( $result->return_code, 0, $cmd); +like( $result->output, '/^HTTP OK - HTTP/1.1 301 Moved Permanently - [\d\.]+ second/', "Output correct: ".$result->output ); + +$cmd = "$command -f follow -u /redirect"; +$result = NPTest->testCmd( $cmd ); +is( $result->return_code, 0, $cmd); +like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 183 bytes in [\d\.]+ second/', "Output correct: ".$result->output ); + +$cmd = "$command -u /redirect -k 'follow: me'"; +$result = NPTest->testCmd( $cmd ); +is( $result->return_code, 0, $cmd); +like( $result->output, '/^HTTP OK - HTTP/1.1 301 Moved Permanently - [\d\.]+ second/', "Output correct: ".$result->output ); + +$cmd = "$command -f follow -u /redirect -k 'follow: me'"; +$result = NPTest->testCmd( $cmd ); +is( $result->return_code, 0, $cmd); +like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 183 bytes in [\d\.]+ second/', "Output correct: ".$result->output ); + -- cgit v1.2.3-74-g34f1