From nobody@FreeBSD.org  Mon Dec  1 01:00:22 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 2510F1065677
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  1 Dec 2008 01:00:22 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 12B978FC1A
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  1 Dec 2008 01:00:22 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id mB110LEf008255
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 1 Dec 2008 01:00:21 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id mB110Lrw008252;
	Mon, 1 Dec 2008 01:00:21 GMT
	(envelope-from nobody)
Message-Id: <200812010100.mB110Lrw008252@www.freebsd.org>
Date: Mon, 1 Dec 2008 01:00:21 GMT
From: Ighighi <ighighi@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch]: sockstat(1) not usable in shell scripts (no white space between entries)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>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:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Dec 01 01:10:00 UTC 2008
>Closed-Date:    Thu May 14 02:45:01 UTC 2009
>Last-Modified:  Thu May 14 02:45:01 UTC 2009
>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:
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: keramida 
Responsible-Changed-When: Fri Jan 23 14:02:37 UTC 2009 
Responsible-Changed-Why:  
The patch looks a bit useful.  Over to sockstat maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=129318 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/129318: commit references a PR
Date: Fri, 30 Jan 2009 14:29:01 +0000 (UTC)

 Author: des
 Date: Fri Jan 30 14:28:50 2009
 New Revision: 187915
 URL: http://svn.freebsd.org/changeset/base/187915
 
 Log:
   Make sure the entries don't run into each other when they're longer than
   the allotted space.
   
   PR:		bin/129318
   Submitted by:	Ighighi <ighighi@gmail.com>
   MFC after:	3 weeks
 
 Modified:
   head/usr.bin/sockstat/sockstat.c
 
 Modified: head/usr.bin/sockstat/sockstat.c
 ==============================================================================
 --- head/usr.bin/sockstat/sockstat.c	Fri Jan 30 13:54:03 2009	(r187914)
 +++ head/usr.bin/sockstat/sockstat.c	Fri Jan 30 14:28:50 2009	(r187915)
 @@ -596,25 +596,25 @@ 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);
  		if (s->vflag & INP_IPV4)
 -			pos += xprintf("4");
 +			pos += xprintf("4 ");
  		if (s->vflag & INP_IPV6)
 -			pos += xprintf("6");
 +			pos += xprintf("6 ");
  		while (pos < 36)
  			pos += xprintf(" ");
  		switch (s->family) {
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: des 
State-Changed-When: Fri Jan 30 14:31:28 UTC 2009 
State-Changed-Why:  
Committed, awaiting MFH 

http://www.freebsd.org/cgi/query-pr.cgi?pr=129318 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/129318: commit references a PR
Date: Thu, 14 May 2009 02:10:47 +0000 (UTC)

 Author: des
 Date: Thu May 14 02:10:31 2009
 New Revision: 192075
 URL: http://svn.freebsd.org/changeset/base/192075
 
 Log:
   MFC r187915: make sure columns don't run into each other.
   
   PR:		bin/129318
 
 Modified:
   stable/7/usr.bin/sockstat/   (props changed)
   stable/7/usr.bin/sockstat/sockstat.c
 
 Modified: stable/7/usr.bin/sockstat/sockstat.c
 ==============================================================================
 --- stable/7/usr.bin/sockstat/sockstat.c	Thu May 14 02:09:09 2009	(r192074)
 +++ stable/7/usr.bin/sockstat/sockstat.c	Thu May 14 02:10:31 2009	(r192075)
 @@ -584,25 +584,25 @@ 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);
  		if (s->vflag & INP_IPV4)
 -			pos += xprintf("4");
 +			pos += xprintf("4 ");
  		if (s->vflag & INP_IPV6)
 -			pos += xprintf("6");
 +			pos += xprintf("6 ");
  		while (pos < 36)
  			pos += xprintf(" ");
  		switch (s->family) {
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: des 
State-Changed-When: Thu May 14 02:45:00 UTC 2009 
State-Changed-Why:  
MFCed 

http://www.freebsd.org/cgi/query-pr.cgi?pr=129318 
>Unformatted:
