File nagios-3.2.3-CVE-2011-1523.patch of Package nagios.import4839

Index: cgi/config.c
===================================================================
--- cgi/config.c.orig
+++ cgi/config.c
@@ -2275,9 +2275,9 @@ void display_command_expansion(void){
 	if ((*to_expand)!='\0'){
 		arg_count[0]=0;
 
-		printf("<TR CLASS='dataEven'><TD CLASS='dataEven'>To expand:</TD><TD CLASS='dataEven'>%s",command_args[0]);
+		printf("<TR CLASS='dataEven'><TD CLASS='dataEven'>To expand:</TD><TD CLASS='dataEven'>%s",escape_string(command_args[0]));
 		for (i=1;(i<MAX_COMMAND_ARGUMENTS)&&command_args[i];i++)
-			printf("!<FONT\n   COLOR='%s'>%s</FONT>",hash_color(i),command_args[i]);
+			printf("!<FONT\n   COLOR='%s'>%s</FONT>",hash_color(i),escape_string(command_args[i]));
 		printf("\n</TD></TR>\n");
 
 		/* check all commands */
Index: cgi/statusmap.c
===================================================================
--- cgi/statusmap.c.orig
+++ cgi/statusmap.c
@@ -2404,7 +2404,7 @@ void print_layer_url(int get_method){
 
 	for(temp_layer=layer_list;temp_layer!=NULL;temp_layer=temp_layer->next){
 		if(get_method==TRUE)
-			printf("&layer=%s",temp_layer->layer_name);
+			printf("&layer=%s",escape_string(temp_layer->layer_name));
 		else
 			printf("<input type='hidden' name='layer' value='%s'>\n",escape_string(temp_layer->layer_name));
 	        }
Index: t/618cgisecurity.t
===================================================================
--- /dev/null
+++ t/618cgisecurity.t
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+#
+# Check that you CGI security errors are fixed
+
+use warnings;
+use strict;
+use Test::More;
+use FindBin qw($Bin);
+
+chdir $Bin or die "Cannot chdir";
+
+my $topdir = "$Bin/..";
+my $cgi_dir = "$topdir/cgi";
+
+plan 'no_plan';
+
+my $output = `NAGIOS_CGI_CONFIG=etc/cgi.cfg REQUEST_METHOD=GET QUERY_STRING="layer=' style=xss:expression(alert('XSS')) '" $cgi_dir/statusmap.cgi`;
+unlike( $output, qr/' style=xss:expression\(alert\('XSS'\)\) '/, "XSS injection not passed straight through" );
+like( $output, qr/&#39; style&#61;xss:expression&#40;alert&#40;&#39;XSS&#39;&#41;&#41; &#39;/, "Expected escaping of quotes" ) || diag $output;
+
+
+$output = `REMOTE_USER=nagiosadmin NAGIOS_CGI_CONFIG=etc/cgi.cfg REQUEST_METHOD=GET QUERY_STRING="type=command&expand=<body onload=alert(666)>" $cgi_dir/config.cgi`;
+unlike( $output, qr/<body onload=alert\(666\)>/, "XSS injection not passed through" ) || diag ($output);
openSUSE Build Service is sponsored by