summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-10-11 15:25:14 +0200
committerLennart Poettering <lennart@poettering.net>2021-10-11 15:37:37 +0200
commita995ce4768928843b4d37ecf46f32fe9e635e38a (patch)
treed39f5ca7fa86da5bd89f815924a44d3fa117e5c4 /src/basic
parent599be274c13c503806c85073d7beb1a155ac27bd (diff)
downloadsystemd-a995ce4768928843b4d37ecf46f32fe9e635e38a.tar.gz
util: define initializer for 'struct ucred' that properly invalidates all fields
i.e. let's make sure to invalid uid/gid to UID_INVAID + GID_INVALID instead of zero.
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/socket-util.c2
-rw-r--r--src/basic/socket-util.h3
2 files changed, 4 insertions, 1 deletions
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c
index 1e66f8700b..94ae90929a 100644
--- a/src/basic/socket-util.c
+++ b/src/basic/socket-util.c
@@ -551,7 +551,7 @@ int getpeername_pretty(int fd, bool include_port, char **ret) {
return -errno;
if (sa.sa.sa_family == AF_UNIX) {
- struct ucred ucred = {};
+ struct ucred ucred = UCRED_INVALID;
/* UNIX connection sockets are anonymous, so let's use
* PID/UID as pretty credentials instead */
diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h
index cb4a92236f..c4fafa084b 100644
--- a/src/basic/socket-util.h
+++ b/src/basic/socket-util.h
@@ -327,3 +327,6 @@ static inline int socket_set_recvfragsize(int fd, int af, bool b) {
}
int socket_get_mtu(int fd, int af, size_t *ret);
+
+/* an initializer for struct ucred that initialized all fields to the invalid value appropriate for each */
+#define UCRED_INVALID { .pid = 0, .uid = UID_INVALID, .gid = GID_INVALID }