summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2020-06-25 15:11:44 +0200
committerStefan Metzmacher <metze@samba.org>2020-07-08 15:54:41 +0000
commit57515a43fbd9ad7071838319aaa663a57fabf440 (patch)
tree430dd87435d57448d05f71b61924b430f7437f1b /source3
parentba66abef8887c71d9fb94980402796f8fbea1d5b (diff)
downloadsamba-57515a43fbd9ad7071838319aaa663a57fabf440.tar.gz
s3:ctdbd_conn: make use of samba_sockaddr in ctdbd_connect()
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>
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/ctdbd_conn.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 79373a72121..9c334764d36 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -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)));