From: Jann Horn Date: Tue, 18 Jun 2013 17:40:36 +0000 (+0200) Subject: fix: use O_CLOEXEC to prevent fds from leaking through other threads X-Git-Url: http://git.thejh.net/?a=commitdiff_plain;h=52b17fa113152cb5549772255e2e3ffe66211c81;p=libjh.git fix: use O_CLOEXEC to prevent fds from leaking through other threads --- diff --git a/io.c b/io.c index d5f9fa5..1a2ddd6 100644 --- a/io.c +++ b/io.c @@ -112,7 +112,7 @@ PUBLIC_FN char *slurp_fd(int fd, size_t *len_out, int flags) { } PUBLIC_FN char *slurp_file(char *path, size_t *len_out, int flags) { - int fd = open(path, O_RDONLY); + int fd = open(path, O_RDONLY|O_CLOEXEC); if (fd == -1) return NULL; char *res = slurp_fd(fd, len_out, flags); int errno_ = errno; @@ -126,7 +126,7 @@ PUBLIC_FN char *slurp_file(char *path, size_t *len_out, int flags) { PUBLIC_FN int write_file(char *path, char *buf, ssize_t len, int open_flags) { if (len == -1) len = strlen(buf); - int fd = open(path, open_flags, 0777); + int fd = open(path, open_flags|O_CLOEXEC, 0777); if (fd == -1) return 1; ssize_t write_res = write_nointr(fd, buf, len, NULL); int write_errno = errno;