-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet-tools-1.60-fgets.patch
41 lines (37 loc) · 1.41 KB
/
net-tools-1.60-fgets.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Fix for when arp_disp_2() is called without opt_n set. If there is a DNS lookup, an
entry is added to /proc/net/arp after fopen(), resulting in a duplicate entry.
--- net-tools-1.60/arp.c.fgets 2005-12-10 14:52:04.000000000 -0500
+++ net-tools-1.60/arp.c 2005-12-11 00:15:59.000000000 -0500
@@ -528,7 +528,7 @@ static int arp_show(char *name)
int type, flags;
FILE *fp;
char *hostname;
- int num, entries = 0, showed = 0;
+ int num, entries, showed = 0;
host[0] = '\0';
@@ -546,18 +546,21 @@ static int arp_show(char *name)
perror(_PATH_PROCNET_ARP);
return (-1);
}
+ /* Count number of entries, in case file changes */
+ for (entries = 0; fgets(line, sizeof(line), fp); entries++);
+ entries--;
+ fseek (fp, 0L, SEEK_SET);
/* Bypass header -- read until newline */
if (fgets(line, sizeof(line), fp) != (char *) NULL) {
strcpy(mask, "-");
strcpy(dev, "-");
/* Read the ARP cache entries. */
- for (; fgets(line, sizeof(line), fp);) {
- num = sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n",
- ip, &type, &flags, hwa, mask, dev);
- if (num < 4)
+ for (num = 0; num < entries; num++) {
+ fgets(line, sizeof(line), fp);
+ if (sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n",
+ ip, &type, &flags, hwa, mask, dev) < 4)
break;
- entries++;
/* if the user specified hw-type differs, skip it */
if (hw_set && (type != hw->type))
continue;