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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <df68542441f77ecedd95a3c29dd61d696f98dfac.1581946818.git.aclaudi@redhat.com>
Date:   Mon, 17 Feb 2020 14:46:18 +0100
From:   Andrea Claudi <aclaudi@...hat.com>
To:     netdev@...r.kernel.org
Cc:     stephen@...workplumber.org, dsahern@...il.com
Subject: [PATCH iproute2 v2] nstat: print useful error messages in abort() cases

When nstat temporary file is corrupted or in some other corner cases,
nstat use abort() to stop its execution. This can puzzle some users,
wondering what is the reason for the crash.

This commit replaces abort() with some meaningful error messages and exit()

Reported-by: Renaud Métrich <rmetrich@...hat.com>
Signed-off-by: Andrea Claudi <aclaudi@...hat.com>
---
 v2: replace two missing abort(), resend to iproute2 instead of iproute2-next

 misc/nstat.c | 47 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/misc/nstat.c b/misc/nstat.c
index 23113b223b22d..425e75ef461ec 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -142,14 +142,19 @@ static void load_good_table(FILE *fp)
 		}
 		/* idbuf is as big as buf, so this is safe */
 		nr = sscanf(buf, "%s%llu%lg", idbuf, &val, &rate);
-		if (nr < 2)
-			abort();
+		if (nr < 2) {
+			fprintf(stderr, "%s:%d: error parsing history file\n",
+				__FILE__, __LINE__);
+			exit(-2);
+		}
 		if (nr < 3)
 			rate = 0;
 		if (useless_number(idbuf))
 			continue;
-		if ((n = malloc(sizeof(*n))) == NULL)
-			abort();
+		if ((n = malloc(sizeof(*n))) == NULL) {
+			perror("nstat: malloc");
+			exit(-1);
+		}
 		n->id = strdup(idbuf);
 		n->val = val;
 		n->rate = rate;
@@ -190,8 +195,11 @@ static void load_ugly_table(FILE *fp)
 		int count1, count2, skip = 0;
 
 		p = strchr(buf, ':');
-		if (!p)
-			abort();
+		if (!p) {
+			fprintf(stderr, "%s:%d: error parsing history file\n",
+				__FILE__, __LINE__);
+			exit(-2);
+		}
 		count1 = count_spaces(buf);
 		*p = 0;
 		idbuf[0] = 0;
@@ -211,8 +219,10 @@ static void load_ugly_table(FILE *fp)
 				strncat(idbuf, p, sizeof(idbuf) - off - 1);
 			}
 			n = malloc(sizeof(*n));
-			if (!n)
-				abort();
+			if (!n) {
+				perror("nstat: malloc");
+				exit(-1);
+			}
 			n->id = strdup(idbuf);
 			n->rate = 0;
 			n->next = db;
@@ -221,18 +231,27 @@ static void load_ugly_table(FILE *fp)
 		}
 		n = db;
 		nread = getline(&buf, &buflen, fp);
-		if (nread == -1)
-			abort();
+		if (nread == -1) {
+			fprintf(stderr, "%s:%d: error parsing history file\n",
+				__FILE__, __LINE__);
+			exit(-2);
+		}
 		count2 = count_spaces(buf);
 		if (count2 > count1)
 			skip = count2 - count1;
 		do {
 			p = strrchr(buf, ' ');
-			if (!p)
-				abort();
+			if (!p) {
+				fprintf(stderr, "%s:%d: error parsing history file\n",
+					__FILE__, __LINE__);
+				exit(-2);
+			}
 			*p = 0;
-			if (sscanf(p+1, "%llu", &n->val) != 1)
-				abort();
+			if (sscanf(p+1, "%llu", &n->val) != 1) {
+				fprintf(stderr, "%s:%d: error parsing history file\n",
+					__FILE__, __LINE__);
+				exit(-2);
+			}
 			/* Trick to skip "dummy" trailing ICMP MIB in 2.4 */
 			if (skip)
 				skip--;
-- 
2.24.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ