route: fix bogus read error when route table is empty
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
09020b1aa8
commit
a75dcd4353
@ -494,6 +494,7 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt)
|
|||||||
{
|
{
|
||||||
char devname[64], flags[16], *sdest, *sgw;
|
char devname[64], flags[16], *sdest, *sgw;
|
||||||
unsigned long d, g, m;
|
unsigned long d, g, m;
|
||||||
|
int r;
|
||||||
int flgs, ref, use, metric, mtu, win, ir;
|
int flgs, ref, use, metric, mtu, win, ir;
|
||||||
struct sockaddr_in s_addr;
|
struct sockaddr_in s_addr;
|
||||||
struct in_addr mask;
|
struct in_addr mask;
|
||||||
@ -504,20 +505,24 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt)
|
|||||||
"Destination Gateway Genmask Flags %s Iface\n",
|
"Destination Gateway Genmask Flags %s Iface\n",
|
||||||
netstatfmt ? " MSS Window irtt" : "Metric Ref Use");
|
netstatfmt ? " MSS Window irtt" : "Metric Ref Use");
|
||||||
|
|
||||||
if (fscanf(fp, "%*[^\n]\n") < 0) { /* Skip the first line. */
|
/* Skip the first line. */
|
||||||
goto ERROR; /* Empty or missing line, or read error. */
|
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) {
|
while (1) {
|
||||||
int r;
|
|
||||||
r = fscanf(fp, "%63s%lx%lx%X%d%d%d%lx%d%d%d\n",
|
r = fscanf(fp, "%63s%lx%lx%X%d%d%d%lx%d%d%d\n",
|
||||||
devname, &d, &g, &flgs, &ref, &use, &metric, &m,
|
devname, &d, &g, &flgs, &ref, &use, &metric, &m,
|
||||||
&mtu, &win, &ir);
|
&mtu, &win, &ir);
|
||||||
if (r != 11) {
|
if (r != 11) {
|
||||||
|
ERROR:
|
||||||
if ((r < 0) && feof(fp)) { /* EOF with no (nonspace) chars read. */
|
if ((r < 0) && feof(fp)) { /* EOF with no (nonspace) chars read. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ERROR:
|
bb_perror_msg_and_die(bb_msg_read_error);
|
||||||
bb_error_msg_and_die("fscanf");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(flgs & RTF_UP)) { /* Skip interfaces that are down. */
|
if (!(flgs & RTF_UP)) { /* Skip interfaces that are down. */
|
||||||
@ -583,7 +588,7 @@ static void INET6_displayroutes(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ERROR:
|
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.
|
/* Do the addr6x shift-and-insert changes to ':'-delimit addresses.
|
||||||
|
Loading…
Reference in New Issue
Block a user