diff options
author | Denys Vlasenko | 2015-02-03 19:42:28 +0100 |
---|---|---|
committer | Denys Vlasenko | 2015-02-04 10:40:10 +0100 |
commit | a75dcd4353566f1a2d64baa642f1276f8ffd6ed4 (patch) | |
tree | d1e084ef83f3e4d6cb9b0c69c21d99668e881abc /networking/route.c | |
parent | 09020b1aa891afaee865caf5fa46fa4ddb42f264 (diff) | |
download | busybox-a75dcd4353566f1a2d64baa642f1276f8ffd6ed4.zip busybox-a75dcd4353566f1a2d64baa642f1276f8ffd6ed4.tar.gz |
route: fix bogus read error when route table is empty
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/route.c')
-rw-r--r-- | networking/route.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/networking/route.c b/networking/route.c index d82b013..65c2fb7 100644 --- a/networking/route.c +++ b/networking/route.c @@ -494,6 +494,7 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt) { char devname[64], flags[16], *sdest, *sgw; unsigned long d, g, m; + int r; int flgs, ref, use, metric, mtu, win, ir; struct sockaddr_in s_addr; struct in_addr mask; @@ -504,20 +505,24 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt) "Destination Gateway Genmask Flags %s Iface\n", netstatfmt ? " MSS Window irtt" : "Metric Ref Use"); - if (fscanf(fp, "%*[^\n]\n") < 0) { /* Skip the first line. */ - goto ERROR; /* Empty or missing line, or read error. */ + /* Skip the first line. */ + r = fscanf(fp, "%*[^\n]\n"); + if (r < 0) { + /* Empty line, read error, or EOF. Yes, if routing table + * is completely empty, /proc/net/route has no header. + */ + goto ERROR; } while (1) { - int r; r = fscanf(fp, "%63s%lx%lx%X%d%d%d%lx%d%d%d\n", devname, &d, &g, &flgs, &ref, &use, &metric, &m, &mtu, &win, &ir); if (r != 11) { + ERROR: if ((r < 0) && feof(fp)) { /* EOF with no (nonspace) chars read. */ break; } - ERROR: - bb_error_msg_and_die("fscanf"); + bb_perror_msg_and_die(bb_msg_read_error); } if (!(flgs & RTF_UP)) { /* Skip interfaces that are down. */ @@ -583,7 +588,7 @@ static void INET6_displayroutes(void) break; } ERROR: - bb_error_msg_and_die("fscanf"); + bb_perror_msg_and_die(bb_msg_read_error); } /* Do the addr6x shift-and-insert changes to ':'-delimit addresses. |