Explorar o código

avoid segfault when host is not given

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@240 f882894a-f735-0410-b71e-b25c423dba1c
Karl DeBisschop %!s(int64=23) %!d(string=hai) anos
pai
achega
b6f64e1290
Modificáronse 1 ficheiros con 7 adicións e 2 borrados
  1. 7 2
      plugins/check_by_ssh.c

+ 7 - 2
plugins/check_by_ssh.c

@@ -283,14 +283,19 @@ process_arguments (int argc, char **argv)
 
 	c = optind;
 	if (hostname == NULL) {
-		if (!is_host (argv[c]))
+		if (c <= argc) {
+			terminate (STATE_UNKNOWN, "%s: You must provide a host name\n", progname);
+		} else if (!is_host (argv[c]))
 			terminate (STATE_UNKNOWN, "%s: Invalid host name %s\n", progname, argv[c]);
 		hostname = argv[c++];
 	}
 
 	if (strlen(remotecmd) == 0) {
 		for (; c < argc; c++)
-			asprintf (&remotecmd, "%s %s", remotecmd, argv[c]);
+			if (strlen(remotecmd) > 0)
+				asprintf (&remotecmd, "%s %s", remotecmd, argv[c]);
+			else
+				asprintf (&remotecmd, "%s", argv[c]);
 	}
 
 	if (commands > 1)