Commit 38c867d2 authored by Stephen Hemminger's avatar Stephen Hemminger Committed by Stephen Hemminger

Add checks for fgets() when reading proc

If expected proc headers are missing, catch and print error.
parent 46dc73a5
...@@ -262,8 +262,11 @@ static int do_tunnels_list(struct ip6_tnl_parm *p) ...@@ -262,8 +262,11 @@ static int do_tunnels_list(struct ip6_tnl_parm *p)
} }
/* skip two lines at the begenning of the file */ /* skip two lines at the begenning of the file */
fgets(buf, sizeof(buf), fp); if (!fgets(buf, sizeof(buf), fp) ||
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) { while (fgets(buf, sizeof(buf), fp) != NULL) {
char name[IFNAMSIZ]; char name[IFNAMSIZ];
......
...@@ -128,7 +128,8 @@ void read_igmp(struct ma_info **result_p) ...@@ -128,7 +128,8 @@ void read_igmp(struct ma_info **result_p)
if (!fp) if (!fp)
return; return;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
fgets(buf, sizeof(buf), fp); if (!fgets(buf, sizeof(buf), fp))
return;
m.addr.family = AF_INET; m.addr.family = AF_INET;
m.addr.bitlen = 32; m.addr.bitlen = 32;
......
...@@ -58,7 +58,8 @@ static void read_viftable(void) ...@@ -58,7 +58,8 @@ static void read_viftable(void)
if (!fp) if (!fp)
return; return;
fgets(buf, sizeof(buf), fp); if (!fgets(buf, sizeof(buf), fp))
return;
while (fgets(buf, sizeof(buf), fp)) { while (fgets(buf, sizeof(buf), fp)) {
int vifi; int vifi;
...@@ -83,7 +84,8 @@ static void read_mroute_list(FILE *ofp) ...@@ -83,7 +84,8 @@ static void read_mroute_list(FILE *ofp)
if (!fp) if (!fp)
return; return;
fgets(buf, sizeof(buf), fp); if (!fgets(buf, sizeof(buf), fp))
return;
while (fgets(buf, sizeof(buf), fp)) { while (fgets(buf, sizeof(buf), fp)) {
inet_prefix maddr, msrc; inet_prefix maddr, msrc;
......
...@@ -407,8 +407,12 @@ static int do_tunnels_list(struct ip_tunnel_parm *p) ...@@ -407,8 +407,12 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
return -1; return -1;
} }
fgets(buf, sizeof(buf), fp); /* skip header lines */
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) { while (fgets(buf, sizeof(buf), fp) != NULL) {
int index, type; int index, type;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment