From 4d1e7a9f186e32eb701ccedeefd677f4a068552b Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Mon, 27 May 2013 11:21:03 -0400 Subject: ifpps: fix bug_on trigger when parsing irq number When parsing irq numbers on e.g. 24 CPU machines, procfs lines can get very long, so our static temporary buffer size will fail here with: Assertion `!(stats->irq_nr == 0)' failed. So allocate it relative to the CPU number. Signed-off-by: Daniel Borkmann --- ifpps.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/ifpps.c b/ifpps.c index 27969ee..e608885 100644 --- a/ifpps.c +++ b/ifpps.c @@ -242,7 +242,8 @@ static int stats_proc_net_dev(const char *ifname, struct ifstat *stats) static int stats_proc_interrupts(char *ifname, struct ifstat *stats) { int ret = -EINVAL, i, cpus, try = 0; - char *ptr, buff[256]; + char *ptr, *buff; + size_t buff_len; struct ethtool_drvinfo drvinf; FILE *fp; @@ -251,12 +252,14 @@ static int stats_proc_interrupts(char *ifname, struct ifstat *stats) panic("Cannot open /proc/interrupts!\n"); cpus = get_number_cpus(); + buff_len = cpus * 128; + buff = xmalloc(buff_len); retry: fseek(fp, 0, SEEK_SET); - memset(buff, 0, sizeof(buff)); + memset(buff, 0, buff_len); - while (fgets(buff, sizeof(buff), fp) != NULL) { - buff[sizeof(buff) - 1] = 0; + while (fgets(buff, buff_len, fp) != NULL) { + buff[buff_len - 1] = 0; ptr = buff; if (strstr(buff, ifname) == NULL) @@ -275,7 +278,7 @@ retry: } } - memset(buff, 0, sizeof(buff)); + memset(buff, 0, buff_len); } if (ret == -EINVAL && try == 0) { @@ -289,6 +292,7 @@ retry: goto retry; } done: + xfree(buff); fclose(fp); return ret; } @@ -296,7 +300,8 @@ done: static int stats_proc_softirqs(struct ifstat *stats) { int i, cpus; - char *ptr, buff[256]; + char *ptr, *buff; + size_t buff_len; FILE *fp; enum { softirqs_net_rx, @@ -308,11 +313,13 @@ static int stats_proc_softirqs(struct ifstat *stats) panic("Cannot open /proc/softirqs!\n"); cpus = get_number_cpus(); + buff_len = cpus * 128; + buff = xmalloc(buff_len); - memset(buff, 0, sizeof(buff)); + memset(buff, 0, buff_len); - while (fgets(buff, sizeof(buff), fp) != NULL) { - buff[sizeof(buff) - 1] = 0; + while (fgets(buff, buff_len, fp) != NULL) { + buff[buff_len - 1] = 0; if ((ptr = strstr(buff, "NET_TX:"))) net_type = softirqs_net_tx; @@ -332,9 +339,10 @@ static int stats_proc_softirqs(struct ifstat *stats) } } - memset(buff, 0, sizeof(buff)); + memset(buff, 0, buff_len); } + xfree(buff); fclose(fp); return 0; } -- cgit v1.2.3-54-g00ecf