]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:ctdbd_conn: make use of samba_sockaddr in ctdbd_connect()
authorStefan Metzmacher <metze@samba.org>
Thu, 25 Jun 2020 13:11:44 +0000 (15:11 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 8 Jul 2020 15:54:41 +0000 (15:54 +0000)
This avoids compiler warnings like this:
dereferencing type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11898

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Günther Deschner <gd@samba.org>
source3/lib/ctdbd_conn.c

index 79373a72121ae204a7d2090dfd3c29ed5fedd016..9c334764d36ccfc5d2f7e028a19b72c3e97f434b 100644 (file)
@@ -24,6 +24,7 @@
 #include "serverid.h"
 #include "ctdbd_conn.h"
 #include "system/select.h"
+#include "lib/util/util_net.h"
 #include "lib/util/sys_rw_data.h"
 #include "lib/util/iov_buf.h"
 #include "lib/util/select.h"
@@ -275,10 +276,17 @@ uint32_t ctdbd_vnn(const struct ctdbd_connection *conn)
 
 static int ctdbd_connect(const char *sockname, int *pfd)
 {
-       struct sockaddr_un addr = { 0, };
+       struct samba_sockaddr addr = {
+               .sa_socklen = sizeof(struct sockaddr_un),
+               .u = {
+                       .un = {
+                               .sun_family = AF_UNIX,
+                       },
+               },
+       };
        int fd;
-       socklen_t salen;
        size_t namelen;
+       int ret;
 
        fd = socket(AF_UNIX, SOCK_STREAM, 0);
        if (fd == -1) {
@@ -287,19 +295,18 @@ static int ctdbd_connect(const char *sockname, int *pfd)
                return err;
        }
 
-       addr.sun_family = AF_UNIX;
-
-       namelen = strlcpy(addr.sun_path, sockname, sizeof(addr.sun_path));
-       if (namelen >= sizeof(addr.sun_path)) {
+       namelen = strlcpy(addr.u.un.sun_path,
+                         sockname,
+                         sizeof(addr.u.un.sun_path));
+       if (namelen >= sizeof(addr.u.un.sun_path)) {
                DEBUG(3, ("%s: Socket name too long: %s\n", __func__,
                          sockname));
                close(fd);
                return ENAMETOOLONG;
        }
 
-       salen = sizeof(struct sockaddr_un);
-
-       if (connect(fd, (struct sockaddr *)(void *)&addr, salen) == -1) {
+       ret = connect(fd, &addr.u.sa, addr.sa_socklen);
+       if (ret == -1) {
                int err = errno;
                DEBUG(1, ("connect(%s) failed: %s\n", sockname,
                          strerror(err)));