mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-10-19 17:37:11 +00:00
nstat: fix load_ugly_table() limits
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: da8034a019
("misc: avoid snprintf warnings in ss and nstat")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
parent
261a5290dd
commit
72cdb77d1a
10
misc/nstat.c
10
misc/nstat.c
@ -177,11 +177,13 @@ static int count_spaces(const char *line)
|
|||||||
|
|
||||||
static void load_ugly_table(FILE *fp)
|
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 *db = NULL;
|
||||||
struct nstat_ent *n;
|
struct nstat_ent *n;
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
while ((nread = getline(&buf, &buflen, fp)) != -1) {
|
||||||
char idbuf[4096];
|
char idbuf[4096];
|
||||||
int off;
|
int off;
|
||||||
char *p;
|
char *p;
|
||||||
@ -218,7 +220,8 @@ static void load_ugly_table(FILE *fp)
|
|||||||
p = next;
|
p = next;
|
||||||
}
|
}
|
||||||
n = db;
|
n = db;
|
||||||
if (fgets(buf, sizeof(buf), fp) == NULL)
|
nread = getline(&buf, &buflen, fp);
|
||||||
|
if (nread == -1)
|
||||||
abort();
|
abort();
|
||||||
count2 = count_spaces(buf);
|
count2 = count_spaces(buf);
|
||||||
if (count2 > count1)
|
if (count2 > count1)
|
||||||
@ -237,6 +240,7 @@ static void load_ugly_table(FILE *fp)
|
|||||||
n = n->next;
|
n = n->next;
|
||||||
} while (p > buf + off + 2);
|
} while (p > buf + off + 2);
|
||||||
}
|
}
|
||||||
|
free(buf);
|
||||||
|
|
||||||
while (db) {
|
while (db) {
|
||||||
n = db;
|
n = db;
|
||||||
|
Loading…
Reference in New Issue
Block a user