bin/129318: [patch]: sockstat(1) not usable in shell scripts (no
white space between entries)
Ighighi
ighighi at gmail.com
Sun Nov 30 17:10:01 PST 2008
>Number: 129318
>Category: bin
>Synopsis: [patch]: sockstat(1) not usable in shell scripts (no white space between entries)
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Mon Dec 01 01:10:00 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator: Ighighi
>Release: RELENG_6
>Organization:
>Environment:
6.4-PRERELEASE FreeBSD 6.4-PRERELEASE #0: Mon Nov 17 07:38:05 VET 2008
>Description:
Currently, sockstat(1) isn't usable in shell scripts to retrieve individual
entries via, e.g, awk(1) because there's no provision for separating entries
with a white space.
>How-To-Repeat:
$ sockstat -4l
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
root sendmail 911 3 tcp4 127.0.0.1:25 *:*
bind named 722 20 tcp4 127.0.0.1:53 *:*
bind named 722 21 tcp4 127.0.0.1:953 *:*
bind named 722 512udp4 127.0.0.1:53 *:*
bind named 722 513udp4 *:64755 *:*
# Note the last 2 lines...
>Fix:
The attached patch (to version 1.19 of sockstat.c in HEAD) gives the following
output:
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
root sendmail 911 3 tcp4 127.0.0.1:25 *:*
bind named 722 20 tcp4 127.0.0.1:53 *:*
bind named 722 21 tcp4 127.0.0.1:953 *:*
bind named 722 512 udp4 127.0.0.1:53 *:*
bind named 722 513 udp4 *:64755 *:*
The vulnerable entries seem to me to be USER, PID, FD and PROTO
Patch attached with submission follows:
--- src/usr.bin/sockstat/sockstat.c.orig 2008-05-19 07:05:11.000000000 -0430
+++ src/usr.bin/sockstat/sockstat.c 2008-11-30 20:09:46.471087728 -0430
@@ -596,18 +596,18 @@ display(void)
continue;
pos = 0;
if ((pwd = getpwuid(xf->xf_uid)) == NULL)
- pos += xprintf("%lu", (u_long)xf->xf_uid);
+ pos += xprintf("%lu ", (u_long)xf->xf_uid);
else
- pos += xprintf("%s", pwd->pw_name);
+ pos += xprintf("%s ", pwd->pw_name);
while (pos < 9)
pos += xprintf(" ");
pos += xprintf("%.10s", getprocname(xf->xf_pid));
while (pos < 20)
pos += xprintf(" ");
- pos += xprintf("%lu", (u_long)xf->xf_pid);
+ pos += xprintf("%lu ", (u_long)xf->xf_pid);
while (pos < 26)
pos += xprintf(" ");
- pos += xprintf("%d", xf->xf_fd);
+ pos += xprintf("%d ", xf->xf_fd);
while (pos < 29)
pos += xprintf(" ");
pos += xprintf("%s", s->protoname);
@@ -615,6 +615,7 @@ display(void)
pos += xprintf("4");
if (s->vflag & INP_IPV6)
pos += xprintf("6");
+ pos += xprintf(" ");
while (pos < 36)
pos += xprintf(" ");
switch (s->family) {
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list