Przeglądaj źródła

Added argc checks before attempting to access argv[]

Corrected return codes and output


git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@306 f882894a-f735-0410-b71e-b25c423dba1c
Jeremy T. Bouse 23 lat temu
rodzic
commit
671cc66eff
1 zmienionych plików z 6 dodań i 5 usunięć
  1. 6 5
      plugins/check_ssh.c

+ 6 - 5
plugins/check_ssh.c

@@ -39,6 +39,7 @@ int ssh_connect (char *haddr, short hport);
 int
 int
 main (int argc, char **argv)
 main (int argc, char **argv)
 {
 {
+	int result;
 
 
 	if (process_arguments (argc, argv) == ERROR)
 	if (process_arguments (argc, argv) == ERROR)
 		usage ("Could not parse arguments\n");
 		usage ("Could not parse arguments\n");
@@ -48,11 +49,11 @@ main (int argc, char **argv)
 	alarm (socket_timeout);
 	alarm (socket_timeout);
 
 
 	/* ssh_connect exits if error is found */
 	/* ssh_connect exits if error is found */
-	ssh_connect (server_name, port);
+	result = ssh_connect (server_name, port);
 
 
 	alarm (0);
 	alarm (0);
 
 
-	return (STATE_OK);
+	return (result);
 }
 }
 
 
 
 
@@ -126,13 +127,13 @@ process_arguments (int argc, char **argv)
 	}
 	}
 
 
 	c = optind;
 	c = optind;
-	if (server_name == NULL && argv[c]) {
+	if (server_name == NULL && c < argc) {
 		if (is_host (argv[c])) {
 		if (is_host (argv[c])) {
 			server_name = argv[c++];
 			server_name = argv[c++];
 		}
 		}
 	}
 	}
 
 
-	if (port == -1 && argv[c]) {
+	if (port == -1 && c < argc) {
 		if (is_intpos (argv[c])) {
 		if (is_intpos (argv[c])) {
 			port = atoi (argv[c++]);
 			port = atoi (argv[c++]);
 		}
 		}
@@ -195,7 +196,7 @@ ssh_connect (char *haddr, short hport)
 		ssh_server = ssh_proto + strspn (ssh_proto, "-0123456789. ");
 		ssh_server = ssh_proto + strspn (ssh_proto, "-0123456789. ");
 		ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0;
 		ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0;
 		printf
 		printf
-			("SSH ok - %s (protocol %s)\n",
+			("SSH OK - %s (protocol %s)\n",
 			 ssh_server, ssh_proto);
 			 ssh_server, ssh_proto);
 		asprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, revision);
 		asprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, revision);
 		send (sd, buffer, strlen (buffer), MSG_DONTWAIT);
 		send (sd, buffer, strlen (buffer), MSG_DONTWAIT);