From 0ea846deb63e157b75527112c78443a144fd9220 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 25 Mar 2017 22:24:48 +0100 Subject: status: correctly align sockaddr_un buffer While at it, also do some more cleanup. --- src/status.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/status.c b/src/status.c index 5d38598..75ae9ec 100644 --- a/src/status.c +++ b/src/status.c @@ -243,15 +243,15 @@ void fastd_status_init(void) { size_t status_socket_len = strlen(conf.status_socket); size_t len = offsetof(struct sockaddr_un, sun_path) + status_socket_len + 1; - uint8_t buf[len]; - memset(buf, 0, len); + uint8_t buf[len] __attribute__((aligned(__alignof__(struct sockaddr_un)))); + memset(buf, 0, offsetof(struct sockaddr_un, sun_path)); - struct sockaddr_un *sa = (void*)buf; + struct sockaddr_un *sa = (struct sockaddr_un *)buf; sa->sun_family = AF_UNIX; memcpy(sa->sun_path, conf.status_socket, status_socket_len+1); - if (bind(ctx.status_fd.fd, (struct sockaddr*)sa, len)) { + if (bind(ctx.status_fd.fd, (struct sockaddr *)sa, len)) { switch (errno) { case EADDRINUSE: exit_error("unable to create status socket: the path `%s' already exists", conf.status_socket); -- cgit v1.2.3