kern/142717: getsockname / getpeername broken

Stefan Buehler freebsd at
Mon Jan 11 13:40:01 UTC 2010

>Number:         142717
>Category:       kern
>Synopsis:       getsockname / getpeername broken
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 11 13:40:01 UTC 2010
>Originator:     Stefan Buehler
>Release:        7.2, 8.0
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.



More information about the freebsd-bugs mailing list