From fd329a1e91cccc8845923af572890ac42b76afc1 Mon Sep 17 00:00:00 2001
From: Holger Weiss <hweiss@users.sourceforge.net>
Date: Sun, 28 Jan 2007 21:46:41 +0000
Subject: Don't try to print `optarg' (which will be a NULL pointer) if an
 unknown command line option was used, as this leads to a segfault on some
 systems.  The unknown option will be printed by getopt(3) anyway.  So, simply
 call print_usage() and exit UNKNOWN via the new usage5() instead.

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1590 f882894a-f735-0410-b71e-b25c423dba1c

diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c
index fbfb331..245946b 100644
--- a/plugins-root/check_dhcp.c
+++ b/plugins-root/check_dhcp.c
@@ -1091,7 +1091,7 @@ int call_getopt(int argc, char **argv){
 			break;
 
 		case '?': /* help */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 			break;
 
 		default:
diff --git a/plugins/check_apt.c b/plugins/check_apt.c
index 902b455..f67ebf9 100644
--- a/plugins/check_apt.c
+++ b/plugins/check_apt.c
@@ -201,7 +201,7 @@ int process_arguments (int argc, char **argv) {
 			break;
 		default:
 			/* print short usage statement if args not parsable */
-			usage_va(_("Unknown argument - %s"), optarg);
+			usage5();
 		}
 	}
 
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index d1cbf93..1675071 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -262,7 +262,7 @@ process_arguments (int argc, char **argv)
 			asprintf (&comm, "%s -%c", comm, c);
 			break;
 		default:									/* help */
-			usage_va(_("Unknown argument - %s"), optarg);
+			usage5();
 		}
 	}
 
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 77df3c2..e850337 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -265,8 +265,8 @@ process_arguments (int argc, char **argv)
     case 'a':
       expected_address = optarg;
       break;
-    default:                  /* usage_va */
-      usage_va(_("Unknown argument - %s"), optarg);
+    default:                  /* usage5 */
+      usage5();
     }
   }
 
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 93af7dc..454f813 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -370,7 +370,7 @@ process_arguments (int argc, char **argv)
       critical = optarg;
       break;
     default: /* args not parsable */
-      usage_va(_("Unknown argument - %s"), optarg);
+      usage5();
     }
   }
 
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 25ca4a8..4dc48b7 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -258,7 +258,7 @@ process_arguments (int argc, char **argv)
 
     switch (c) {
     case '?':                 /* print short usage statement if args not parsable */
-      usage2 (_("Unknown argument"), optarg);
+      usage5 ();
     case 'h':                 /* help */
       print_help ();
       exit (STATE_OK);
diff --git a/plugins/check_game.c b/plugins/check_game.c
index a785b51..79abec3 100644
--- a/plugins/check_game.c
+++ b/plugins/check_game.c
@@ -249,7 +249,7 @@ process_arguments (int argc, char **argv)
         return ERROR;
       break;
     default: /* args not parsable */
-      usage_va(_("Unknown argument - %s"), optarg);
+      usage5();
     }
   }
 
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c
index 31a76bd..8a60ce8 100644
--- a/plugins/check_hpjd.c
+++ b/plugins/check_hpjd.c
@@ -351,7 +351,7 @@ process_arguments (int argc, char **argv)
 			print_help ();
 			exit (STATE_OK);
 		case '?':									/* help */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		}
 	}
 
diff --git a/plugins/check_http.c b/plugins/check_http.c
index b81f214..d1f3998 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -225,7 +225,7 @@ process_arguments (int argc, char **argv)
 
     switch (c) {
     case '?': /* usage */
-      usage2 (_("Unknown argument"), optarg);
+      usage5 ();
       break;
     case 'h': /* help */
       print_help ();
diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c
index 14d27b3..234f23b 100644
--- a/plugins/check_ide_smart.c
+++ b/plugins/check_ide_smart.c
@@ -212,7 +212,7 @@ main (int argc, char *argv[])
 			print_revision (progname, revision);
 			return STATE_OK;
 		default:
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		}
 	}
 
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c
index 60872cf..12ea071 100644
--- a/plugins/check_ldap.c
+++ b/plugins/check_ldap.c
@@ -325,7 +325,7 @@ process_arguments (int argc, char **argv)
 #endif
 			break;
 		default:
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		}
 	}
 
diff --git a/plugins/check_load.c b/plugins/check_load.c
index 562eaf5..3d00432 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -236,7 +236,7 @@ process_arguments (int argc, char **argv)
 			print_help ();
 			exit (STATE_OK);
 		case '?':									/* help */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		}
 	}
 
diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c
index 7cee31e..4abe1d7 100644
--- a/plugins/check_mrtg.c
+++ b/plugins/check_mrtg.c
@@ -243,7 +243,7 @@ process_arguments (int argc, char **argv)
 			print_help ();
 			exit (STATE_OK);
 		case '?':									/* help */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		}
 	}
 
diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c
index adaf9e2..e587e5c 100644
--- a/plugins/check_mrtgtraf.c
+++ b/plugins/check_mrtgtraf.c
@@ -277,7 +277,7 @@ process_arguments (int argc, char **argv)
 			print_help ();
 			exit (STATE_OK);
 		case '?':									/* help */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		}
 	}
 
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index e10211f..573ec96 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -308,7 +308,7 @@ process_arguments (int argc, char **argv)
 			verbose++;
 			break;
 		case '?':									/* help */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		}
 	}
 
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c
index ecb7e7f..bb62eec 100644
--- a/plugins/check_mysql_query.c
+++ b/plugins/check_mysql_query.c
@@ -240,7 +240,7 @@ process_arguments (int argc, char **argv)
 			critical = optarg;
 			break;
 		case '?':									/* help */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		}
 	}
 
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c
index a6ae71f..5703e60 100644
--- a/plugins/check_nagios.c
+++ b/plugins/check_nagios.c
@@ -258,7 +258,7 @@ process_arguments (int argc, char **argv)
 			verbose++;
 			break;
 		default:									/* print short usage_va statement if args not parsable */
-			usage_va(_("Unknown argument - %s"), optarg);
+			usage5();
 		}
 	}
 
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index 44203db..fe47a58 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -492,7 +492,7 @@ int process_arguments(int argc, char **argv){
 		switch (c)
 			{
 			case '?': /* print short usage statement if args not parsable */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 			case 'h': /* help */
 				print_help();
 				exit(STATE_OK);
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index d6e1dd5..3ed8f34 100644
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
@@ -694,7 +694,7 @@ int process_arguments(int argc, char **argv){
 			break;
 		case '?':
 			/* print short usage statement if args not parsable */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 			break;
 		}
 	}
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c
index 91797dc..53ac2e0 100644
--- a/plugins/check_nwstat.c
+++ b/plugins/check_nwstat.c
@@ -1355,7 +1355,7 @@ int process_arguments(int argc, char **argv) {
 		switch (c)
 			{
 			case '?': /* print short usage statement if args not parsable */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 			case 'h': /* help */
 				print_help();
 				exit(STATE_OK);
diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c
index 2aca8ea..25a7785 100644
--- a/plugins/check_overcr.c
+++ b/plugins/check_overcr.c
@@ -341,7 +341,7 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':									/* print short usage statement if args not parsable */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		case 'h':									/* help */
 			print_help ();
 			exit (STATE_OK);
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index 41c5141..cbff8d7 100644
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
@@ -225,7 +225,7 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':     /* usage */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		case 'h':     /* help */
 			print_help ();
 			exit (STATE_OK);
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index ca40920..aa686a6 100644
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
@@ -211,7 +211,7 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':	/* usage */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		case 'h':	/* help */
 			print_help ();
 			exit (STATE_OK);
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index d9e2a67..da7e9f0 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -359,7 +359,7 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':									/* help */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		case 'h':									/* help */
 			print_help ();
 			exit (STATE_OK);
diff --git a/plugins/check_radius.c b/plugins/check_radius.c
index b1bb928..4b340c3 100644
--- a/plugins/check_radius.c
+++ b/plugins/check_radius.c
@@ -235,7 +235,7 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':									/* print short usage statement if args not parsable */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		case 'h':									/* help */
 			print_help ();
 			exit (OK);
diff --git a/plugins/check_real.c b/plugins/check_real.c
index 2d24e14..0ccc1c0 100644
--- a/plugins/check_real.c
+++ b/plugins/check_real.c
@@ -368,7 +368,7 @@ process_arguments (int argc, char **argv)
 			print_help ();
 			exit (STATE_OK);
 		case '?':									/* usage */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		}
 	}
 
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 94214ee..94b97c4 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -664,7 +664,7 @@ process_arguments (int argc, char **argv)
 			print_help ();
 			exit (STATE_OK);
 		case '?':									/* help */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		}
 	}
 
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 1e1657b..d9e0078 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -444,7 +444,7 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':	/* usage */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		case 'h':	/* help */
 			print_help ();
 			exit (STATE_OK); 
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index 1c24e58..afe44c9 100644
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
@@ -128,7 +128,7 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':									/* help */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		case 'V':									/* version */
 			print_revision (progname, revision);
 			exit (STATE_OK);
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 59c1ecf..1903a00 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -468,7 +468,7 @@ process_arguments (int argc, char **argv)
 			print_help ();
 			exit (STATE_OK);
 		case '?':									/* error */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		}
 	}
 
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index faa3ced..7e1bd38 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -443,7 +443,7 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':                 /* print short usage statement if args not parsable */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		case 'h':                 /* help */
 			print_help ();
 			exit (STATE_OK);
diff --git a/plugins/check_time.c b/plugins/check_time.c
index ca42056..d3af3b0 100644
--- a/plugins/check_time.c
+++ b/plugins/check_time.c
@@ -232,7 +232,7 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':									/* print short usage statement if args not parsable */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		case 'h':									/* help */
 			print_help ();
 			exit (STATE_OK);
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index 280b3fb..56438bb 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -494,7 +494,7 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':									/* help */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		case 'H':									/* hostname */
 			if (is_host (optarg)) {
 				server_address = optarg;
diff --git a/plugins/check_users.c b/plugins/check_users.c
index 0c62e3b..8e5f23d 100644
--- a/plugins/check_users.c
+++ b/plugins/check_users.c
@@ -156,7 +156,7 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':									/* print short usage statement if args not parsable */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		case 'h':									/* help */
 			print_help ();
 			exit (STATE_OK);
diff --git a/plugins/negate.c b/plugins/negate.c
index 45c0326..8b2dff0 100644
--- a/plugins/negate.c
+++ b/plugins/negate.c
@@ -189,7 +189,7 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':     /* help */
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 			break;
 		case 'h':     /* help */
 			print_help ();
diff --git a/plugins/urlize.c b/plugins/urlize.c
index 7793e9a..612dd14 100644
--- a/plugins/urlize.c
+++ b/plugins/urlize.c
@@ -100,7 +100,7 @@ main (int argc, char **argv)
 			break;
 		case '?':
 		default:
-			usage2 (_("Unknown argument"), optarg);
+			usage5 ();
 		}
 	}
 
diff --git a/plugins/utils.c b/plugins/utils.c
index 2b3acce..7e1e58a 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -94,6 +94,13 @@ usage4 (const char *msg)
 	exit (STATE_UNKNOWN);
 }
 
+void
+usage5 (void)
+{
+	print_usage();
+	exit (STATE_UNKNOWN);
+}
+
 char *
 clean_revstring (const char *revstring)
 {
diff --git a/plugins/utils.h b/plugins/utils.h
index 0d00ce8..f15a7b1 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -80,8 +80,9 @@ int max_state (int a, int b);
 void usage (const char *) __attribute__((noreturn));
 void usage2(const char *, const char *) __attribute__((noreturn));
 void usage3(const char *, int) __attribute__((noreturn));
-void usage4(const char *);
-void usage_va(const char *fmt, ...);
+void usage4(const char *) __attribute__((noreturn));
+void usage5(void) __attribute__((noreturn));
+void usage_va(const char *fmt, ...) __attribute__((noreturn));
 
 const char *state_text (int);
 
-- 
cgit v0.10-9-g596f

