af_unix unix_getname: return size for unnamed sockets too small?

From: Marcus Meissner
Date: Wed Feb 02 2011 - 12:40:22 EST


Hi,

In net/unix/af_unix.c::unix_getname() there is a small problem:

if (!u->addr) {
sunaddr->sun_family = AF_UNIX;
sunaddr->sun_path[0] = 0; // not copied out
*uaddr_len = sizeof(short);
} else {
struct unix_address *addr = u->addr;

*uaddr_len = addr->len;
memcpy(sunaddr, addr->name, *uaddr_len);
}

The if (!u->addr) case will not copy out the \0 in the sun_path, as
uaddr_len is just the size of sun_family.

(Shown by socat crashing after decoding gethostname return and expected
sun_path to be a valid string (and not seeing the \0)).

Should it perhaps be *uaddr_len = sizeof(short)+sizeof(char)?

Ciao, Marcus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/