diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-10-07 02:34:17 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-10-07 02:34:17 +0200 |
commit | 0e098b15c76e222f7de381203c0c35a75a5b2f24 (patch) | |
tree | 864b2b06696c7fcc4d0c29daa3121574c52f004b /src/sd-daemon.c | |
parent | e983b76024342278a0377eae116c925f2567776e (diff) |
util: never use sizeof(sa_family_t) when calculating sockaddr sizes
Diffstat (limited to 'src/sd-daemon.c')
-rw-r--r-- | src/sd-daemon.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/sd-daemon.c b/src/sd-daemon.c index 9c23b917f9..e12fb0483a 100644 --- a/src/sd-daemon.c +++ b/src/sd-daemon.c @@ -40,6 +40,7 @@ #include <string.h> #include <stdarg.h> #include <stdio.h> +#include <stddef.h> #include "sd-daemon.h" @@ -227,7 +228,7 @@ int sd_is_socket(int fd, int family, int type, int listening) { if (getsockname(fd, &sockaddr.sa, &l) < 0) return -errno; - if (l < sizeof(sa_family_t)) + if (l < offsetof(struct sockaddr_un, sun_path)) return -EINVAL; return sockaddr.sa.sa_family == family; @@ -253,7 +254,7 @@ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port if (getsockname(fd, &sockaddr.sa, &l) < 0) return -errno; - if (l < sizeof(sa_family_t)) + if (l < offsetof(struct sockaddr_un, sun_path)) return -EINVAL; if (sockaddr.sa.sa_family != AF_INET && @@ -295,7 +296,7 @@ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t if (getsockname(fd, &sockaddr.sa, &l) < 0) return -errno; - if (l < sizeof(sa_family_t)) + if (l < offsetof(struct sockaddr_un, sun_path)) return -EINVAL; if (sockaddr.sa.sa_family != AF_UNIX) @@ -307,17 +308,17 @@ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t if (length <= 0) /* Unnamed socket */ - return l == sizeof(sa_family_t); + return l == offsetof(struct sockaddr_un, sun_path); if (path[0]) /* Normal path socket */ return - (l >= sizeof(sa_family_t) + length + 1) && + (l >= offsetof(struct sockaddr_un, sun_path) + length + 1) && memcmp(path, sockaddr.un.sun_path, length+1) == 0; else /* Abstract namespace socket */ return - (l == sizeof(sa_family_t) + length) && + (l == offsetof(struct sockaddr_un, sun_path) + length) && memcmp(path, sockaddr.un.sun_path, length) == 0; } @@ -366,7 +367,7 @@ int sd_notify(int unset_environment, const char *state) { memset(&msghdr, 0, sizeof(msghdr)); msghdr.msg_name = &sockaddr; - msghdr.msg_namelen = sizeof(sa_family_t) + strlen(e); + msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(e); if (msghdr.msg_namelen > sizeof(struct sockaddr_un)) msghdr.msg_namelen = sizeof(struct sockaddr_un); |