-
Notifications
You must be signed in to change notification settings - Fork 0
/
net-tools-1.60-netstat_inode.patch
186 lines (161 loc) · 6.42 KB
/
net-tools-1.60-netstat_inode.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
--- net-tools-1.60/netstat.c.inode 2006-02-23 09:28:23.000000000 +0100
+++ net-tools-1.60/netstat.c 2006-02-23 09:33:57.000000000 +0100
@@ -231,7 +231,7 @@
static struct prg_node {
struct prg_node *next;
- int inode;
+ unsigned long inode;
char name[PROGNAME_WIDTH];
char scon[SELINUX_WIDTH];
} *prg_hash[PRG_HASH_SIZE];
@@ -268,7 +268,7 @@
/* NOT working as of glibc-2.0.7: */
#undef DIRENT_HAVE_D_TYPE_WORKS
-static void prg_cache_add(int inode, char *name, char *scon)
+static void prg_cache_add(unsigned long inode, char *name, char *scon)
{
unsigned hi = PRG_HASHIT(inode);
struct prg_node **pnp,*pn;
@@ -332,15 +332,16 @@
prg_cache_loaded=0;
}
-static void extract_type_1_socket_inode(const char lname[], long * inode_p) {
+static void extract_type_1_socket_inode(const char lname[], unsigned long * inode_p, int * status) {
/* If lname is of the form "socket:[12345]", extract the "12345"
- as *inode_p. Otherwise, return -1 as *inode_p.
+ as *inode_p. Otherwise, return -1 as *status.
*/
- if (strlen(lname) < PRG_SOCKET_PFXl+3) *inode_p = -1;
- else if (memcmp(lname, PRG_SOCKET_PFX, PRG_SOCKET_PFXl)) *inode_p = -1;
- else if (lname[strlen(lname)-1] != ']') *inode_p = -1;
+ *status = 0;
+ if (strlen(lname) < PRG_SOCKET_PFXl+3) *status = -1;
+ else if (memcmp(lname, PRG_SOCKET_PFX, PRG_SOCKET_PFXl)) *status = -1;
+ else if (lname[strlen(lname)-1] != ']') *status = -1;
else {
char inode_str[strlen(lname + 1)]; /* e.g. "12345" */
const int inode_str_len = strlen(lname) - PRG_SOCKET_PFXl - 1;
@@ -348,28 +349,30 @@
strncpy(inode_str, lname+PRG_SOCKET_PFXl, inode_str_len);
inode_str[inode_str_len] = '\0';
- *inode_p = strtol(inode_str,&serr,0);
- if (!serr || *serr || *inode_p < 0 || *inode_p >= INT_MAX)
- *inode_p = -1;
+ errno = 0;
+ *inode_p = strtoul(inode_str,&serr,0);
+ if (!serr || *serr || errno)
+ *status = -1;
}
}
-static void extract_type_2_socket_inode(const char lname[], long * inode_p) {
+static void extract_type_2_socket_inode(const char lname[], unsigned long * inode_p, int * status) {
/* If lname is of the form "[0000]:12345", extract the "12345"
- as *inode_p. Otherwise, return -1 as *inode_p.
+ as *inode_p. Otherwise, return -1 as *status.
*/
- if (strlen(lname) < PRG_SOCKET_PFX2l+1) *inode_p = -1;
- else if (memcmp(lname, PRG_SOCKET_PFX2, PRG_SOCKET_PFX2l)) *inode_p = -1;
+ if (strlen(lname) < PRG_SOCKET_PFX2l+1) *status = -1;
+ else if (memcmp(lname, PRG_SOCKET_PFX2, PRG_SOCKET_PFX2l)) *status = -1;
else {
char *serr;
- *inode_p=strtol(lname + PRG_SOCKET_PFX2l,&serr,0);
- if (!serr || *serr || *inode_p < 0 || *inode_p >= INT_MAX)
- *inode_p = -1;
+ errno = 0;
+ *inode_p=strtoul(lname + PRG_SOCKET_PFX2l,&serr,0);
+ if (!serr || *serr || errno)
+ *status = -1;
}
}
@@ -380,11 +383,12 @@
char line[LINE_MAX],eacces=0;
int procfdlen,fd,cmdllen,lnamelen;
char lname[30],cmdlbuf[512],finbuf[PROGNAME_WIDTH];
- long inode;
+ unsigned long inode;
const char *cs,*cmdlp;
DIR *dirproc=NULL,*dirfd=NULL;
struct dirent *direproc,*direfd;
security_context_t scon=NULL;
+ int status;
if (prg_cache_loaded || !flag_prg) return;
prg_cache_loaded=1;
@@ -424,11 +428,11 @@
lnamelen=readlink(line,lname,sizeof(lname)-1);
lname[lnamelen] = '\0'; /*make it a null-terminated string*/
- extract_type_1_socket_inode(lname, &inode);
+ extract_type_1_socket_inode(lname, &inode, &status);
- if (inode < 0) extract_type_2_socket_inode(lname, &inode);
+ if (status < 0) extract_type_2_socket_inode(lname, &inode, &status);
- if (inode < 0) continue;
+ if (status < 0) continue;
if (!cmdlp) {
if (procfdlen - PATH_FD_SUFFl + PATH_CMDLINEl >=
@@ -732,7 +736,7 @@
printf("%-10s ", pw->pw_name);
else
printf("%-10d ", uid);
- printf("%-10ld ",inode);
+ printf("%-10lu ",inode);
}
if (flag_prg)
printf("%-" PROGNAME_WIDTHs "s",prg_cache_get(inode));
@@ -921,7 +925,7 @@
return;
num = sscanf(line,
- "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
+ "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %lu %512s\n",
&d, local_addr, &local_port, rem_addr, &rem_port, &state,
&txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
@@ -1064,7 +1068,7 @@
more[0] = '\0';
num = sscanf(line,
- "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
+ "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %lu %512s\n",
&d, local_addr, &local_port,
rem_addr, &rem_port, &state,
&txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
@@ -1206,7 +1210,7 @@
more[0] = '\0';
num = sscanf(line,
- "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
+ "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %lu %512s\n",
&d, local_addr, &local_port, rem_addr, &rem_port, &state,
&txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
@@ -1320,9 +1324,9 @@
static int has = 0;
char path[MAXPATHLEN], ss_flags[32];
char *ss_proto, *ss_state, *ss_type;
- int num, state, type, inode;
+ int num, state, type;
void *d;
- unsigned long refcnt, proto, flags;
+ unsigned long refcnt, proto, flags, inode;
if (nr == 0) {
if (strstr(line, "Inode"))
@@ -1330,14 +1334,14 @@
return;
}
path[0] = '\0';
- num = sscanf(line, "%p: %lX %lX %lX %X %X %d %s",
+ num = sscanf(line, "%p: %lX %lX %lX %X %X %lu %s",
&d, &refcnt, &proto, &flags, &type, &state, &inode, path);
if (num < 6) {
fprintf(stderr, _("warning, got bogus unix line.\n"));
return;
}
if (!(has & HAS_INODE))
- snprintf(path,sizeof(path),"%d",inode);
+ snprintf(path,sizeof(path),"%lu",inode);
if (!flag_all) {
if ((state == SS_UNCONNECTED) && (flags & SO_ACCEPTCON)) {
@@ -1429,7 +1433,7 @@
printf("%-5s %-6ld %-11s %-10s %-13s ",
ss_proto, refcnt, ss_flags, ss_type, ss_state);
if (has & HAS_INODE)
- printf("%-6d ",inode);
+ printf("%-6lu ",inode);
else
printf("- ");
if (flag_prg)