From c53a5c4f3e17496fa944c80cf911f8780de7ae67 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 5 Dec 2005 15:22:38 +0000 Subject: r12073: fix vlgrind error, calculate the correct size for memcpy() and don't assume out_len is >= sizeof(*in_addr) metze (This used to be commit 61dbe9e5070085117b12b5b37cf0e7fe4342e2a3) --- source4/lib/socket_wrapper/socket_wrapper.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source4/lib/socket_wrapper') diff --git a/source4/lib/socket_wrapper/socket_wrapper.c b/source4/lib/socket_wrapper/socket_wrapper.c index d9f61f7e3c..d517a4c1b5 100644 --- a/source4/lib/socket_wrapper/socket_wrapper.c +++ b/source4/lib/socket_wrapper/socket_wrapper.c @@ -357,16 +357,23 @@ static int sockaddr_convert_from_un(const struct socket_info *si, socklen_t un_addrlen, int family, struct sockaddr *out_addr, - socklen_t *out_len) + socklen_t *_out_addrlen) { - if (out_addr == NULL || out_len == NULL) + socklen_t out_addrlen; + + if (out_addr == NULL || _out_addrlen == NULL) return 0; if (un_addrlen == 0) { - *out_len = 0; + *_out_addrlen = 0; return 0; } + out_addrlen = *_out_addrlen; + if (out_addrlen > un_addrlen) { + out_addrlen = un_addrlen; + } + switch (family) { case AF_INET: switch (si->type) { @@ -377,10 +384,10 @@ static int sockaddr_convert_from_un(const struct socket_info *si, errno = ESOCKTNOSUPPORT; return -1; } - return convert_un_in(in_addr, (struct sockaddr_in *)out_addr, out_len); + return convert_un_in(in_addr, (struct sockaddr_in *)out_addr, _out_addrlen); case AF_UNIX: - memcpy(out_addr, in_addr, sizeof(*in_addr)); - *out_len = sizeof(*in_addr); + memcpy(out_addr, in_addr, out_addrlen); + *_out_addrlen = out_addrlen; return 0; default: break; -- cgit