summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-daemon/sd-daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd/sd-daemon/sd-daemon.c')
-rw-r--r--src/libsystemd/sd-daemon/sd-daemon.c33
1 files changed, 9 insertions, 24 deletions
diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c
index 9e9b115557..218210f234 100644
--- a/src/libsystemd/sd-daemon/sd-daemon.c
+++ b/src/libsystemd/sd-daemon/sd-daemon.c
@@ -1,6 +1,4 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-***/
#include <errno.h>
#include <limits.h>
@@ -21,6 +19,7 @@
#include "alloc-util.h"
#include "fd-util.h"
#include "fs-util.h"
+#include "io-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
@@ -446,12 +445,8 @@ _public_ int sd_pid_notify_with_fds(
const int *fds,
unsigned n_fds) {
- union sockaddr_union sockaddr = {
- .sa.sa_family = AF_UNIX,
- };
- struct iovec iovec = {
- .iov_base = (char*) state,
- };
+ union sockaddr_union sockaddr = {};
+ struct iovec iovec;
struct msghdr msghdr = {
.msg_iov = &iovec,
.msg_iovlen = 1,
@@ -461,7 +456,7 @@ _public_ int sd_pid_notify_with_fds(
struct cmsghdr *cmsg = NULL;
const char *e;
bool send_ucred;
- int r;
+ int r, salen;
if (!state) {
r = -EINVAL;
@@ -477,14 +472,9 @@ _public_ int sd_pid_notify_with_fds(
if (!e)
return 0;
- /* Must be an abstract socket, or an absolute path */
- if (!IN_SET(e[0], '@', '/') || e[1] == 0) {
- r = -EINVAL;
- goto finish;
- }
-
- if (strlen(e) > sizeof(sockaddr.un.sun_path)) {
- r = -EINVAL;
+ salen = sockaddr_un_set_path(&sockaddr.un, e);
+ if (salen < 0) {
+ r = salen;
goto finish;
}
@@ -496,13 +486,8 @@ _public_ int sd_pid_notify_with_fds(
(void) fd_inc_sndbuf(fd, SNDBUF_SIZE);
- iovec.iov_len = strlen(state);
-
- strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path));
- if (sockaddr.un.sun_path[0] == '@')
- sockaddr.un.sun_path[0] = 0;
-
- msghdr.msg_namelen = SOCKADDR_UN_LEN(sockaddr.un);
+ iovec = IOVEC_MAKE_STRING(state);
+ msghdr.msg_namelen = salen;
send_ucred =
(pid != 0 && pid != getpid_cached()) ||