netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: David Ahern <dsahern@gmail.com>,
	Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev <netdev@vger.kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	Eric Dumazet <eric.dumazet@gmail.com>
Subject: [PATCH iproute2] nstat: fix load_ugly_table() limits
Date: Fri, 21 Dec 2018 22:53:35 -0800	[thread overview]
Message-ID: <20181222065335.3518-1-edumazet@google.com> (raw)

A recent change reduced max line length from 4096 to 2048 bytes,
but we already have lines above the 2048 threshold, and we keep
adding more SNMP counters in linux.

Switch to getline() and do not worry about future kernel changes.

Fixes: da8034a01904 ("misc: avoid snprintf warnings in ss and nstat")
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 misc/nstat.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/misc/nstat.c b/misc/nstat.c
index 88f1c7698243235b12f58cd067afce488af1be4c..653580eae0603327ea654510ae1f23a79578c1fe 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -177,11 +177,13 @@ static int count_spaces(const char *line)
 
 static void load_ugly_table(FILE *fp)
 {
-	char buf[2048];
+	char *buf = NULL;
+	size_t buflen = 0;
+	ssize_t nread;
 	struct nstat_ent *db = NULL;
 	struct nstat_ent *n;
 
-	while (fgets(buf, sizeof(buf), fp) != NULL) {
+	while ((nread = getline(&buf, &buflen, fp)) != -1) {
 		char idbuf[4096];
 		int  off;
 		char *p;
@@ -218,7 +220,8 @@ static void load_ugly_table(FILE *fp)
 			p = next;
 		}
 		n = db;
-		if (fgets(buf, sizeof(buf), fp) == NULL)
+		nread = getline(&buf, &buflen, fp);
+		if (nread == -1)
 			abort();
 		count2 = count_spaces(buf);
 		if (count2 > count1)
@@ -237,6 +240,7 @@ static void load_ugly_table(FILE *fp)
 				n = n->next;
 		} while (p > buf + off + 2);
 	}
+	free(buf);
 
 	while (db) {
 		n = db;
-- 
2.20.1.415.g653613c723-goog

             reply	other threads:[~2018-12-22 17:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-22  6:53 Eric Dumazet [this message]
2019-01-01  5:54 ` [PATCH iproute2] nstat: fix load_ugly_table() limits Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181222065335.3518-1-edumazet@google.com \
    --to=edumazet@google.com \
    --cc=dsahern@gmail.com \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).