diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2016-05-19 18:12:17 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2016-05-31 13:07:15 +0200 |
commit | 45e11be651dbd3855a35de4abd2922e5b9d4b963 (patch) | |
tree | a98a1fe79bd675a7bd4aaa824205a20ea9fd71f8 /src/util/util.h | |
parent | 518f5b83fd546e3188da01e4743ddb27a574e08f (diff) | |
download | sssd-45e11be651dbd3855a35de4abd2922e5b9d4b963.tar.gz sssd-45e11be651dbd3855a35de4abd2922e5b9d4b963.tar.xz sssd-45e11be651dbd3855a35de4abd2922e5b9d4b963.zip |
Do not leak fds in case of failures setting up a child process
Resolves:
https://fedorahosted.org/sssd/ticket/3006
The handling of open pipes in failure cases was suboptimal. Moreover,
the faulty logic was copied all over the place. This patch introduces
helper macros to:
- initialize the pipe endpoints to -1
- close an open pipe fd and set it to -1 afterwards
- close both ends unless already closed
These macros are used in the child handling code.
The patch also uses child_io_destructor in the p11_child code for safer
fd handling.
Reviewed-by: Petr Cech <pcech@redhat.com>
Diffstat (limited to 'src/util/util.h')
-rw-r--r-- | src/util/util.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/util.h b/src/util/util.h index 11054c106..b4ab14e71 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -84,6 +84,20 @@ #define FLAGS_INTERACTIVE 0x0002 #define FLAGS_PID_FILE 0x0004 +#define PIPE_INIT { -1, -1 } + +#define PIPE_FD_CLOSE(fd) do { \ + if (fd != -1) { \ + close(fd); \ + fd = -1; \ + } \ +} while(0); + +#define PIPE_CLOSE(p) do { \ + PIPE_FD_CLOSE(p[0]); \ + PIPE_FD_CLOSE(p[1]); \ +} while(0); + #ifndef talloc_zfree #define talloc_zfree(ptr) do { talloc_free(discard_const(ptr)); ptr = NULL; } while(0) #endif |