From: Stephen Hemminger Date: Wed, 9 Mar 2011 18:41:09 +0000 (-0800) Subject: Add checks for fgets() when reading proc X-Git-Tag: v2.6.39~13^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38c867d2a82d6f2b60450550fbaaadc5d9c77579;p=thirdparty%2Fiproute2.git Add checks for fgets() when reading proc If expected proc headers are missing, catch and print error. --- diff --git a/ip/ip6tunnel.c b/ip/ip6tunnel.c index f0db5aa04..b08723a85 100644 --- a/ip/ip6tunnel.c +++ b/ip/ip6tunnel.c @@ -262,8 +262,11 @@ static int do_tunnels_list(struct ip6_tnl_parm *p) } /* skip two lines at the begenning of the file */ - fgets(buf, sizeof(buf), fp); - fgets(buf, sizeof(buf), fp); + if (!fgets(buf, sizeof(buf), fp) || + !fgets(buf, sizeof(buf), fp)) { + fprintf(stderr, "/proc/net/dev read error\n"); + return -1; + } while (fgets(buf, sizeof(buf), fp) != NULL) { char name[IFNAMSIZ]; diff --git a/ip/ipmaddr.c b/ip/ipmaddr.c index 44ffdfcfa..ec326bc00 100644 --- a/ip/ipmaddr.c +++ b/ip/ipmaddr.c @@ -128,7 +128,8 @@ void read_igmp(struct ma_info **result_p) if (!fp) return; memset(&m, 0, sizeof(m)); - fgets(buf, sizeof(buf), fp); + if (!fgets(buf, sizeof(buf), fp)) + return; m.addr.family = AF_INET; m.addr.bitlen = 32; diff --git a/ip/ipmroute.c b/ip/ipmroute.c index 977143cc3..a4389f578 100644 --- a/ip/ipmroute.c +++ b/ip/ipmroute.c @@ -58,7 +58,8 @@ static void read_viftable(void) if (!fp) return; - fgets(buf, sizeof(buf), fp); + if (!fgets(buf, sizeof(buf), fp)) + return; while (fgets(buf, sizeof(buf), fp)) { int vifi; @@ -83,7 +84,8 @@ static void read_mroute_list(FILE *ofp) if (!fp) return; - fgets(buf, sizeof(buf), fp); + if (!fgets(buf, sizeof(buf), fp)) + return; while (fgets(buf, sizeof(buf), fp)) { inet_prefix maddr, msrc; diff --git a/ip/iptunnel.c b/ip/iptunnel.c index fe5e3f968..f038f0a6a 100644 --- a/ip/iptunnel.c +++ b/ip/iptunnel.c @@ -407,8 +407,12 @@ static int do_tunnels_list(struct ip_tunnel_parm *p) return -1; } - fgets(buf, sizeof(buf), fp); - fgets(buf, sizeof(buf), fp); + /* skip header lines */ + if (!fgets(buf, sizeof(buf), fp) || + !fgets(buf, sizeof(buf), fp)) { + fprintf(stderr, "/proc/net/dev read error\n"); + return -1; + } while (fgets(buf, sizeof(buf), fp) != NULL) { int index, type;