]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/commitdiff
Add checks for fgets() when reading proc
authorStephen Hemminger <stephen.hemminger@vyatta.com>
Wed, 9 Mar 2011 18:41:09 +0000 (10:41 -0800)
committerStephen Hemminger <shemminger@vyatta.com>
Tue, 12 Apr 2011 21:23:17 +0000 (14:23 -0700)
If expected proc headers are missing, catch and print error.

ip/ip6tunnel.c
ip/ipmaddr.c
ip/ipmroute.c
ip/iptunnel.c

index f0db5aa04c98b5bae354b2dd1d9009c6b55e3b09..b08723a85df5fd3d4ec6ac6d3af10dd46046f3c2 100644 (file)
@@ -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];
index 44ffdfcfa253c56be6c3e3860ab1e504e81f4f3e..ec326bc007454419962b5f707cc93ecb46698b05 100644 (file)
@@ -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;
index 977143cc3dfa9495e3277224473fc9d7f45409ec..a4389f578786c0d3d4fd193168b51b7d499e0f5e 100644 (file)
@@ -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;
index fe5e3f968855648700cd1d5ac8ce15b27ba9d282..f038f0a6a77f9edce6ce64e3de99953db7d27f06 100644 (file)
@@ -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;