From 18717cad039d251ff9b3c4813f6e67911e0ebebc Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 23 Dec 2009 19:31:41 +0100 Subject: [PATCH] tsocket: allow AF_UNIX sockaddrs smaller than sizeof(sockaddr_un) This is needed as getpeername() truncates the length to 2 if the peer socket has no name. metze (cherry picked from commit 4784c8c3bea98592486ca973d57c99671eb68cb2) Signed-off-by: Stefan Metzmacher (cherry picked from commit e9f7d271e2a96d5dbce63bc454c68930cbc52d62) --- lib/tsocket/tsocket_bsd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c index 201788e9223..6f6b4229f9f 100644 --- a/lib/tsocket/tsocket_bsd.c +++ b/lib/tsocket/tsocket_bsd.c @@ -210,12 +210,13 @@ int _tsocket_address_bsd_from_sockaddr(TALLOC_CTX *mem_ctx, struct tsocket_address *addr; struct tsocket_address_bsd *bsda; + if (sa_socklen < sizeof(sa->sa_family)) { + errno = EINVAL; + return -1; + } + switch (sa->sa_family) { case AF_UNIX: - if (sa_socklen < sizeof(struct sockaddr_un)) { - errno = EINVAL; - return -1; - } break; case AF_INET: if (sa_socklen < sizeof(struct sockaddr_in)) { -- 2.11.4.GIT