From nobody@FreeBSD.org  Mon Jan 11 13:39:22 2010
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 38830106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 11 Jan 2010 13:39: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 266738FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 11 Jan 2010 13:39:22 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o0BDdLcx089932
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 11 Jan 2010 13:39:21 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o0BDdLMK089922;
	Mon, 11 Jan 2010 13:39:21 GMT
	(envelope-from nobody)
Message-Id: <201001111339.o0BDdLMK089922@www.freebsd.org>
Date: Mon, 11 Jan 2010 13:39:21 GMT
From: Stefan Buehler <freebsd@stbuehler.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: getsockname / getpeername broken
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         142717
>Category:       kern
>Synopsis:       [libc] getsockname(2) / getpeername(2) broken
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    brucec
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 11 13:40:01 UTC 2010
>Closed-Date:    Mon Apr 19 17:32:13 UTC 2010
>Last-Modified:  Mon Apr 19 17:32:13 UTC 2010
>Originator:     Stefan Buehler
>Release:        7.2, 8.0
>Organization:
>Environment:
>Description:
I'm not using freebsd myself, but i got a bug report and had a look at the source.

What i want to do is:

	socklen_t l = 0;
	static struct sockaddr sa;

	if (-1 == getsockname(fd, &sa, &l)) {
		return NULL;
	}

	struct sockaddr* saddr = malloc(l);
	getsockname(fd, saddr, &l);

	return saddr;

The posix manpage clearly states that getsockname stores the length of
the address in l and that the data is truncated. The freebsd implementation
truncates the data, but it also stores the truncated length.
>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->brucec  
Responsible-Changed-By: brucec 
Responsible-Changed-When: Wed Feb 17 15:10:54 UTC 2010 
Responsible-Changed-Why:  
Take 

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

From: Bruce Cran <bruce@cran.org.uk>
To: bug-followup@freebsd.org,
 freebsd@stbuehler.de
Cc:  
Subject: Re: kern/142717: [libc] getsockname(2) / getpeername(2) broken
Date: Wed, 17 Feb 2010 17:50:14 +0000

 --nextPart2129569.ir8pQsKeaI
 Content-Type: Text/Plain;
   charset="us-ascii"
 Content-Transfer-Encoding: quoted-printable
 
 I think there can be an differing interpretation of whether "the address"=20
 refers to the complete structure that would have been returned, or only the=
 =20
 number of bytes that have been filled in.  Whereas most manual pages are=20
 unclear about what length value is returned when the address is truncated, =
 the=20
 IBM z/OS manual page appears to be the clearest - it says:
 
 "namelen must be initialized to indicate the size of the space pointed to b=
 y=20
 name and is set to the number of bytes copied into the space before the cal=
 l=20
 returns."
 and
 "The sa_len member of the store structure contains the length of the=20
 untruncated address."
 
 =2D-=20
 Bruce Cran
 
 --nextPart2129569.ir8pQsKeaI
 Content-Type: application/pgp-signature; name=signature.asc 
 Content-Description: This is a digitally signed message part.
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.14 (FreeBSD)
 
 iQEcBAABAgAGBQJLfCxbAAoJEFeHpytq9vmez3sIALNmdvsIYVuYqjCzwgS3OTh+
 gwFWsvSiBAJl4eOU7AWIUOe45O4fZXK9ZK83o0L3lp7hXGEpR4thFw2ogsKTUpln
 C+51cRgFk+rSN9c4yFHBS6t/6I05Ky52R+zz/JOkQ90jl/h9iOwXB2lPqy389ta7
 d3Gf2wm1T6CsspuEqqLIJyyJbfRTWG3/QddjSQ3WXEQgCrr3J+j2XPPt1UyBL+4n
 NgmZ97IMN0zyxe0p9HZDHyPIM8L7trIRK2HaAd3sW/MyEM5zt7iiiWropVHCqamB
 xuW2Yi3VD1uJxr4wgXB1nGayFE2fxSP4RTCUZ3rmdDeXKFRowhf+TTEJYZqoAdk=
 =CDpE
 -----END PGP SIGNATURE-----
 
 --nextPart2129569.ir8pQsKeaI--
State-Changed-From-To: open->feedback  
State-Changed-By: brucec 
State-Changed-When: Sun Feb 28 18:31:10 UTC 2010 
State-Changed-Why:  
Since different implementations have interpreted the wording differently,  
I'm not sure this is a bug in FreeBSD. Can this PR be closed? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=142717 
State-Changed-From-To: feedback->closed 
State-Changed-By: brucec 
State-Changed-When: Mon Apr 19 17:31:44 UTC 2010 
State-Changed-Why:  
Feedback timeout. 

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