diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 1437df6cf3..7868e53fb6 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -964,9 +964,11 @@ static int parse_container_unix_address(sd_bus *b, const char **p, char **guid) } else b->nspid = 0; - b->sockaddr.un.sun_family = AF_UNIX; - /* Note that we use the old /var/run prefix here, to increase compatibility with really old containers */ - strncpy(b->sockaddr.un.sun_path, "/var/run/dbus/system_bus_socket", sizeof(b->sockaddr.un.sun_path)); + b->sockaddr.un = (struct sockaddr_un) { + .sun_family = AF_UNIX, + /* Note that we use the old /var/run prefix here, to increase compatibility with really old containers */ + .sun_path = "/var/run/dbus/system_bus_socket", + }; b->sockaddr_size = SOCKADDR_UN_LEN(b->sockaddr.un); b->is_local = false; diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 134c4c3b5d..d756d0aed0 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2815,7 +2815,8 @@ static int setup_sd_notify_child(void) { static const int one = 1; int fd = -1; union sockaddr_union sa = { - .sa.sa_family = AF_UNIX, + .un.sun_family = AF_UNIX, + .un.sun_path = NSPAWN_NOTIFY_SOCKET_PATH, }; int r; @@ -2826,11 +2827,10 @@ static int setup_sd_notify_child(void) { (void) mkdir_parents(NSPAWN_NOTIFY_SOCKET_PATH, 0755); (void) unlink(NSPAWN_NOTIFY_SOCKET_PATH); - strncpy(sa.un.sun_path, NSPAWN_NOTIFY_SOCKET_PATH, sizeof(sa.un.sun_path)); r = bind(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)); if (r < 0) { safe_close(fd); - return log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path); + return log_error_errno(errno, "bind(" NSPAWN_NOTIFY_SOCKET_PATH ") failed: %m"); } r = userns_lchown(NSPAWN_NOTIFY_SOCKET_PATH, 0, 0); diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index df9ceef7ce..84909b3e15 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -101,8 +101,11 @@ struct udev_ctrl *udev_ctrl_new_from_fd(int fd) { if (r < 0) log_warning_errno(errno, "could not set SO_PASSCRED: %m"); - uctrl->saddr.un.sun_family = AF_LOCAL; - strscpy(uctrl->saddr.un.sun_path, sizeof(uctrl->saddr.un.sun_path), "/run/udev/control"); + uctrl->saddr.un = (struct sockaddr_un) { + .sun_family = AF_UNIX, + .sun_path = "/run/udev/control", + }; + uctrl->addrlen = SOCKADDR_UN_LEN(uctrl->saddr.un); return uctrl; }