summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2008-11-08 02:32:03 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2008-11-08 02:32:03 (GMT)
commit6c5f781bc58cef0a28ab2dbc7eeb1391df3ba009 (patch)
treeccc0cd52ce067193efecc1b4a05c9b86c5364a61 /plugins
parent288b742ed61bb62a210fdd3614d4e3883aa82407 (diff)
downloadmonitoring-plugins-6c5f781bc58cef0a28ab2dbc7eeb1391df3ba009.tar.gz
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
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_http.c4
-rwxr-xr-xplugins/tests/check_http.t31
2 files changed, 32 insertions, 3 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index df5daf2..0746741 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -815,7 +815,9 @@ check_http (void)
815 for ((pos = strtok(http_opt_headers[i], INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER))) 815 for ((pos = strtok(http_opt_headers[i], INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER)))
816 asprintf (&buf, "%s%s\r\n", buf, pos); 816 asprintf (&buf, "%s%s\r\n", buf, pos);
817 } 817 }
818 free(http_opt_headers); 818 /* This cannot be free'd here because a redirection will then try to access this and segfault */
819 /* Covered in a testcase in tests/check_http.t */
820 /* free(http_opt_headers); */
819 } 821 }
820 822
821 /* optionally send the authentication info */ 823 /* optionally send the authentication info */
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index d54932e..c5f9080 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -28,7 +28,8 @@ if ($pid) {
28 #print "child\n"; 28 #print "child\n";
29 29
30 my $d = HTTP::Daemon->new( 30 my $d = HTTP::Daemon->new(
31 LocalPort => $port 31 LocalPort => $port,
32 LocalAddr => "127.0.0.1",
32 ) || die; 33 ) || die;
33 print "Please contact me at: <URL:", $d->url, ">\n"; 34 print "Please contact me at: <URL:", $d->url, ">\n";
34 while (my $c = $d->accept ) { 35 while (my $c = $d->accept ) {
@@ -57,6 +58,12 @@ if ($pid) {
57 $c->send_basic_header; 58 $c->send_basic_header;
58 $c->send_crlf; 59 $c->send_crlf;
59 $c->send_response($r->method.":".$r->content); 60 $c->send_response($r->method.":".$r->content);
61 } elsif ($r->url->path eq "/redirect") {
62 $c->send_redirect( "/redirect2" );
63 } elsif ($r->url->path eq "/redirect2") {
64 $c->send_basic_header;
65 $c->send_crlf;
66 $c->send_response("redirected");
60 } else { 67 } else {
61 $c->send_error(RC_FORBIDDEN); 68 $c->send_error(RC_FORBIDDEN);
62 } 69 }
@@ -73,7 +80,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
73} 80}
74 81
75if (-x "./check_http") { 82if (-x "./check_http") {
76 plan tests => 39; 83 plan tests => 47;
77} else { 84} else {
78 plan skip_all => "No check_http compiled"; 85 plan skip_all => "No check_http compiled";
79} 86}
@@ -180,3 +187,23 @@ $result = NPTest->testCmd( $cmd );
180is( $result->return_code, 0, $cmd); 187is( $result->return_code, 0, $cmd);
181like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); 188like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output );
182 189
190$cmd = "$command -u /redirect";
191$result = NPTest->testCmd( $cmd );
192is( $result->return_code, 0, $cmd);
193like( $result->output, '/^HTTP OK - HTTP/1.1 301 Moved Permanently - [\d\.]+ second/', "Output correct: ".$result->output );
194
195$cmd = "$command -f follow -u /redirect";
196$result = NPTest->testCmd( $cmd );
197is( $result->return_code, 0, $cmd);
198like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 183 bytes in [\d\.]+ second/', "Output correct: ".$result->output );
199
200$cmd = "$command -u /redirect -k 'follow: me'";
201$result = NPTest->testCmd( $cmd );
202is( $result->return_code, 0, $cmd);
203like( $result->output, '/^HTTP OK - HTTP/1.1 301 Moved Permanently - [\d\.]+ second/', "Output correct: ".$result->output );
204
205$cmd = "$command -f follow -u /redirect -k 'follow: me'";
206$result = NPTest->testCmd( $cmd );
207is( $result->return_code, 0, $cmd);
208like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 183 bytes in [\d\.]+ second/', "Output correct: ".$result->output );
209