swrap: Fix recvmsg() with UDP
authorAndreas Schneider <asn@samba.org>
Tue, 27 Oct 2015 08:26:40 +0000 (09:26 +0100)
committerAndreas Schneider <asn@samba.org>
Tue, 27 Oct 2015 13:58:04 +0000 (14:58 +0100)
This worked if the unix path was bigger than sizeof(struct sockaddr_in6).
With a short unix socket pathname the buffer was to small to store the
address and convert_un_in() failed.

Thanks to Grigorij Demidov <grigorii.demidov@nic.cz>

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
src/socket_wrapper.c

index 6691738526d6424d639ab9cb2fd89fe70953d266..3c0c2797d3073ab661c1f133a5956e9d3d899007 100644 (file)
@@ -4603,6 +4603,9 @@ static ssize_t swrap_recvmsg(int s, struct msghdr *omsg, int flags)
        struct swrap_address from_addr = {
                .sa_socklen = sizeof(struct sockaddr_un),
        };
+       struct swrap_address convert_addr = {
+               .sa_socklen = sizeof(struct sockaddr_storage),
+       };
        struct socket_info *si;
        struct msghdr msg;
        struct iovec tmp;
@@ -4661,6 +4664,13 @@ static ssize_t swrap_recvmsg(int s, struct msghdr *omsg, int flags)
        }
 #endif
 
+       /*
+        * We convert the unix address to a IP address so we need a buffer
+        * which can store the address in case of SOCK_DGRAM, see below.
+        */
+       msg.msg_name = &convert_addr.sa;
+       msg.msg_namelen = convert_addr.sa_socklen;
+
        rc = swrap_recvmsg_after(s,
                                 si,
                                 &msg,