Просмотр исходного кода

Fixed crash from check_nt when -H unspecified or given multiple times (sf.net #2731755, debian #521097)

Matthias Eble 17 лет назад
Родитель
Сommit
8e4c885ee1
3 измененных файлов с 7 добавлено и 2 удалено
  1. 1 0
      NEWS
  2. 2 1
      plugins/check_nt.c
  3. 4 1
      plugins/tests/check_nt.t

+ 1 - 0
NEWS

@@ -23,6 +23,7 @@ This file documents the major additions and syntax changes between releases.
 	check_http --onredirect=sticky follows using the same IP address (sf.net #2550208)
 	check_http --onredirect=stickyport also follows the same port
 	Fixed coredump from check_nt when invalid drive is specified (#2179754 - Olli Hauer)
+	Fixed crash from check_nt when -H unspecified or given multiple times (sf.net #2731755, debian #521097)
 	Fixed passing of quotes in OID for check_snmp (#1985230 - Jan Wagner, patch by John Barbuto)
 	Fixed check_http sending HTTP/1.0 with v1.1 headers (#2638765)
 	Fixed check_http not timing-out on redirects

+ 2 - 1
plugins/check_nt.c

@@ -522,7 +522,6 @@ int process_arguments(int argc, char **argv){
 				print_revision(progname, NP_VERSION);
 				exit(STATE_OK);
 			case 'H': /* hostname */
-				if (server_address)	free(server_address);
 				server_address = optarg;
 				break;
 			case 's': /* password */
@@ -585,6 +584,8 @@ int process_arguments(int argc, char **argv){
 			}
 
 	}
+	if (server_address == NULL)
+		usage4 (_("You must provide a server address or host name"));
 
 	if (vars_to_check==CHECK_NONE)
 		return ERROR;

+ 4 - 1
plugins/tests/check_nt.t

@@ -59,7 +59,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
 }
 
 if (-x "./check_nt") {
-	plan tests => 4;
+	plan tests => 5;
 } else {
 	plan skip_all => "No check_nt compiled";
 }
@@ -75,3 +75,6 @@ $result = NPTest->testCmd( "$command -v USEDDISKSPACE -l d" );
 is( $result->return_code, 3, "USEDDISKSPACE d - invalid");
 is( $result->output, "Free disk space : Invalid drive", "Output right" );
 
+$result = NPTest->testCmd( "./check_nt -v USEDDISKSPACE -l d" );
+is( $result->return_code, 3, "Fail if -H missing");
+