diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/ask-password-api.c | 2 | ||||
-rw-r--r-- | src/shared/util.c | 10 | ||||
-rw-r--r-- | src/shared/util.h | 2 |
3 files changed, 14 insertions, 0 deletions
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 0a61dafc59..44ebc58491 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -475,6 +475,8 @@ int ask_password_agent( goto finish; } + cmsg_close_all(&msghdr); + if (n <= 0) { log_error("Message too short"); continue; diff --git a/src/shared/util.c b/src/shared/util.c index deb9839633..dc6528013b 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -8110,3 +8110,13 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k return -1; } + +void cmsg_close_all(struct msghdr *mh) { + struct cmsghdr *cmsg; + + assert(mh); + + for (cmsg = CMSG_FIRSTHDR(mh); cmsg; cmsg = CMSG_NXTHDR(mh, cmsg)) + if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) + close_many((int*) CMSG_DATA(cmsg), (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int)); +} diff --git a/src/shared/util.h b/src/shared/util.h index 45cb09443d..759d053c25 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -1080,3 +1080,5 @@ void sigkill_wait(pid_t *pid); #define _cleanup_sigkill_wait_ _cleanup_(sigkill_wait) int syslog_parse_priority(const char **p, int *priority, bool with_facility); + +void cmsg_close_all(struct msghdr *mh); |