diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-12-27 17:18:02 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-01-05 13:55:08 +0100 |
commit | 8b7f989a5824869a5ca9983b225758a8c2fd8f4a (patch) | |
tree | b4a12e42eeb1ce150c3e72537f6c7833ba5011ba /src/basic | |
parent | 89220e2fb6d49df31bed4205c9c84883749483bc (diff) | |
download | systemd-8b7f989a5824869a5ca9983b225758a8c2fd8f4a.tar.gz |
socket-util: explicitly ensure there's one trailing NUL byte on AF_UNIX socket addresses
AF_UNIX socket addresses aren't necessarily NUL terminated, however
they are usually used as strings which are assumed to be NUL terminated.
Let's hence add an extra byte to the end of the sockaddr_un structure,
that contains this NUL byte, simply for safety reasons.
Note that actually this patch changes exactly nothing IRL, as the other
sockaddr structures already are large enough to accomodate for an extra
NUL byte. The size of the union hence doesn't change at all by doing
this. The entire value of this patch is hence in the philosophical
feeling of safety, and by making something explicit that before was
implicit.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/socket-util.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h index 83af91dbef..49c937aef5 100644 --- a/src/basic/socket-util.h +++ b/src/basic/socket-util.h @@ -36,16 +36,26 @@ #include "util.h" union sockaddr_union { + /* The minimal, abstract version */ struct sockaddr sa; + + /* The libc provided version that allocates "enough room" for every protocol */ + struct sockaddr_storage storage; + + /* Protoctol-specific implementations */ struct sockaddr_in in; struct sockaddr_in6 in6; struct sockaddr_un un; struct sockaddr_nl nl; - struct sockaddr_storage storage; struct sockaddr_ll ll; struct sockaddr_vm vm; + /* Ensure there is enough space to store Infiniband addresses */ uint8_t ll_buffer[offsetof(struct sockaddr_ll, sll_addr) + CONST_MAX(ETH_ALEN, INFINIBAND_ALEN)]; + + /* Ensure there is enough space after the AF_UNIX sun_path for one more NUL byte, just to be sure that the path + * component is always followed by at least one NUL byte. */ + uint8_t un_buffer[sizeof(struct sockaddr_un) + 1]; }; typedef struct SocketAddress { |