[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#645469: bind() fails for AF_UNIX sockets with EINVAL

Jonathan Nieder wrote:

> --- i/sys/kern/uipc_syscalls.c
> +++ w/sys/kern/uipc_syscalls.c
> @@ -1703,11 +1703,18 @@ getsockaddr(namp, uaddr, len)
>  		sa->sa_len = len;
> +		datalen = len - offsetof(struct sockaddr, sa_data[0]);
> +		p = memchr(sa->sa_data, '\0', datalen);
> +		if (p)
> +			sa_len = p - (const char *)sa;
>  		*namp = sa;

Ah, this is clearly broken since it applies to address types
other than AF_UNIX.  Guarding it with a test of sa_family would
take care of that.

More importantly, there is the question you raised of whether this
should be done in userspace by libc instead.  That would avoid
upstream having to wonder, "why should we care what happens when
someone using a BSD4.3-style bind() calls our BSD4.4-style kernel"?
So it's tempting.

Reply to: