diff options
author | Ruediger Meier | 2018-03-07 10:40:23 +0100 |
---|---|---|
committer | Karel Zak | 2018-03-07 11:50:05 +0100 |
commit | eb10dbc159dd0d7dfd7c213c0351eef6e17d45ef (patch) | |
tree | 07dc3adcbab0c4cc865d822796b0d057a9b89960 /misc-utils/uuidd.c | |
parent | libmount: fix fs pattern usage in mount --all (diff) | |
download | kernel-qcow2-util-linux-eb10dbc159dd0d7dfd7c213c0351eef6e17d45ef.tar.gz kernel-qcow2-util-linux-eb10dbc159dd0d7dfd7c213c0351eef6e17d45ef.tar.xz kernel-qcow2-util-linux-eb10dbc159dd0d7dfd7c213c0351eef6e17d45ef.zip |
uuidd: don't truncate long socket paths
This was the error
uuidd: couldn't bind unix socket /var/tmp/portage/sys-apps/util-linux-2.31.1/work/util-linux-2.31.1-abi_x86_64.amd64/tests/output/uuid/uuiddkOcTUuoZ7kaP3: Address already in use
because the socket path was truncated to 108 chars which was luckily
an existing directory.
Now we abort early with "uuidd: socket name too long: ... "
Reported-by: Thomas Deutschmann <whissi@gentoo.org>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'misc-utils/uuidd.c')
-rw-r--r-- | misc-utils/uuidd.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c index e7c25cfa1..ca2ae8cf7 100644 --- a/misc-utils/uuidd.c +++ b/misc-utils/uuidd.c @@ -118,8 +118,8 @@ static int call_daemon(const char *socket_path, int op, char *buf, } srv_addr.sun_family = AF_UNIX; - strncpy(srv_addr.sun_path, socket_path, sizeof(srv_addr.sun_path)); - srv_addr.sun_path[sizeof(srv_addr.sun_path) - 1] = '\0'; + assert(strlen(socket_path) < sizeof(srv_addr.sun_path)); + xstrncpy(srv_addr.sun_path, socket_path, sizeof(srv_addr.sun_path)); if (connect(s, (const struct sockaddr *) &srv_addr, sizeof(struct sockaddr_un)) < 0) { @@ -252,8 +252,8 @@ static int create_socket(struct uuidd_cxt_t *uuidd_cxt, * Create the address we will be binding to. */ my_addr.sun_family = AF_UNIX; - strncpy(my_addr.sun_path, socket_path, sizeof(my_addr.sun_path)); - my_addr.sun_path[sizeof(my_addr.sun_path) - 1] = '\0'; + assert(strlen(socket_path) < sizeof(my_addr.sun_path)); + xstrncpy(my_addr.sun_path, socket_path, sizeof(my_addr.sun_path)); unlink(socket_path); save_umask = umask(0); if (bind(s, (const struct sockaddr *) &my_addr, @@ -636,6 +636,10 @@ int main(int argc, char **argv) } } + if (strlen(socket_path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) { + errx(EXIT_FAILURE, _("socket name too long: %s"), socket_path); + } + if (!no_pid && !pidfile_path) pidfile_path = UUIDD_PIDFILE_PATH; |