shared: introduce cmsg_close_all() call

The call iterates through cmsg list and closes all fds passed via
SCM_RIGHTS.

This patch also ensures the call is used wherever appropriate, where we
might get spurious fds sent and we should better close them, then leave
them lying around.
This commit is contained in:
Lennart Poettering
2015-02-18 19:42:24 +01:00
parent 6e646d22f6
commit 1c8da04446
6 changed files with 28 additions and 11 deletions
+2
View File
@@ -475,6 +475,8 @@ int ask_password_agent(
goto finish;
}
cmsg_close_all(&msghdr);
if (n <= 0) {
log_error("Message too short");
continue;
+10
View File
@@ -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));
}
+2
View File
@@ -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);