lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240423160652.68304-1-stephen@networkplumber.org>
Date: Tue, 23 Apr 2024 09:05:43 -0700
From: Stephen Hemminger <stephen@...workplumber.org>
To: netdev@...r.kernel.org
Cc: Stephen Hemminger <stephen@...workplumber.org>
Subject: [PATCH iproute2] use missing argument helper

There is a helper in utilities to handle missing argument,
but it was not being used consistently.

Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
---
 ip/ip.c               | 10 +++++-----
 ip/iproute_lwtunnel.c |  7 ++-----
 ip/rtmon.c            |  4 ++--
 tc/f_u32.c            |  2 +-
 tc/m_sample.c         |  7 ++-----
 tc/tc.c               |  2 +-
 6 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/ip/ip.c b/ip/ip.c
index e51fa206..eb492139 100644
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -203,15 +203,15 @@ int main(int argc, char **argv)
 			argc--;
 			argv++;
 			if (argc <= 1)
-				usage();
+				missarg("loop count");
 			max_flush_loops = atoi(argv[1]);
 		} else if (matches(opt, "-family") == 0) {
 			argc--;
 			argv++;
 			if (argc <= 1)
-				usage();
+				missarg("family type");
 			if (strcmp(argv[1], "help") == 0)
-				usage();
+				do_help(argc, argv);
 			else
 				preferred_family = read_family(argv[1]);
 			if (preferred_family == AF_UNSPEC)
@@ -258,7 +258,7 @@ int main(int argc, char **argv)
 			argc--;
 			argv++;
 			if (argc <= 1)
-				usage();
+				missarg("batch file");
 			batch_file = argv[1];
 		} else if (matches(opt, "-brief") == 0) {
 			++brief;
@@ -272,7 +272,7 @@ int main(int argc, char **argv)
 			argc--;
 			argv++;
 			if (argc <= 1)
-				usage();
+				missarg("rcvbuf size");
 			if (get_unsigned(&size, argv[1], 0)) {
 				fprintf(stderr, "Invalid rcvbuf size '%s'\n",
 					argv[1]);
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index 94985972..b4df4348 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -2228,11 +2228,8 @@ int lwt_parse_encap(struct rtattr *rta, size_t len, int *argcp, char ***argvp,
 		invarg("\"encap type\" value is invalid\n", *argv);
 
 	NEXT_ARG();
-	if (argc <= 1) {
-		fprintf(stderr,
-			"Error: unexpected end of line after \"encap\"\n");
-		exit(-1);
-	}
+	if (argc <= 1)
+		missarg("encap type");
 
 	nest = rta_nest(rta, len, encap_attr);
 	switch (type) {
diff --git a/ip/rtmon.c b/ip/rtmon.c
index aad9968f..08105d68 100644
--- a/ip/rtmon.c
+++ b/ip/rtmon.c
@@ -82,7 +82,7 @@ main(int argc, char **argv)
 			argc--;
 			argv++;
 			if (argc <= 1)
-				usage();
+				missarg("family type");
 			if (strcmp(argv[1], "inet") == 0)
 				family = AF_INET;
 			else if (strcmp(argv[1], "inet6") == 0)
@@ -108,7 +108,7 @@ main(int argc, char **argv)
 			argc--;
 			argv++;
 			if (argc <= 1)
-				usage();
+				missarg("file");
 			file = argv[1];
 		} else if (matches(argv[1], "link") == 0) {
 			llink = 1;
diff --git a/tc/f_u32.c b/tc/f_u32.c
index a0699636..d7679e7a 100644
--- a/tc/f_u32.c
+++ b/tc/f_u32.c
@@ -663,7 +663,7 @@ static int parse_mark(int *argc_p, char ***argv_p, struct nlmsghdr *n)
 	struct tc_u32_mark mark;
 
 	if (argc <= 1)
-		return -1;
+		missarg("mark");
 
 	if (get_u32(&mark.val, *argv, 0)) {
 		fprintf(stderr, "Illegal \"mark\" value\n");
diff --git a/tc/m_sample.c b/tc/m_sample.c
index 642ec3a6..3baf1d55 100644
--- a/tc/m_sample.c
+++ b/tc/m_sample.c
@@ -45,11 +45,8 @@ static int parse_sample(const struct action_util *a, int *argc_p, char ***argv_p
 	__u32 group;
 	__u32 rate;
 
-	if (argc <= 1) {
-		fprintf(stderr, "sample bad argument count %d\n", argc);
-		usage();
-		return -1;
-	}
+	if (argc <= 1)
+		missarg("sample count");
 
 	if (matches(*argv, "sample") == 0) {
 		NEXT_ARG();
diff --git a/tc/tc.c b/tc/tc.c
index 7edff7e3..26e6f69c 100644
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -289,7 +289,7 @@ int main(int argc, char **argv)
 		} else if (matches(argv[1], "-batch") == 0) {
 			argc--;	argv++;
 			if (argc <= 1)
-				usage();
+				missarg("batch file");
 			batch_file = argv[1];
 		} else if (matches(argv[1], "-netns") == 0) {
 			NEXT_ARG();
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ