diff options
author | Jilles Tjoelker <jilles@FreeBSD.org> | 2012-12-17 10:38:51 +0000 |
---|---|---|
committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2012-12-17 10:38:51 +0000 |
commit | 571d9493ad5e471fb72a615c34808df4bf2eab56 (patch) | |
tree | b1c948dd83e286f99bbcbd51cb1a0fa52990bd00 /lib/libc/iconv | |
parent | 790ffa6cfd20d753763f956188519dab798f00d0 (diff) | |
download | src-571d9493ad5e471fb72a615c34808df4bf2eab56.tar.gz src-571d9493ad5e471fb72a615c34808df4bf2eab56.zip |
libc/iconv: Fix race condition with setting FD_CLOEXEC.
A fork/exec could happen between open and fcntl, leaking a file descriptor.
Using O_CLOEXEC fixes this and as a side effect simplifies the code.
NetBSD already had this (I checked this after making the change myself).
Reviewed by: gabor
Notes
Notes:
svn path=/head/; revision=244350
Diffstat (limited to 'lib/libc/iconv')
-rw-r--r-- | lib/libc/iconv/citrus_mmap.c | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/lib/libc/iconv/citrus_mmap.c b/lib/libc/iconv/citrus_mmap.c index dd5d059786eb..2aaf73ca0b5f 100644 --- a/lib/libc/iconv/citrus_mmap.c +++ b/lib/libc/iconv/citrus_mmap.c @@ -57,12 +57,8 @@ _citrus_map_file(struct _citrus_region * __restrict r, _region_init(r, NULL, 0); - if ((fd = open(path, O_RDONLY)) == -1) + if ((fd = open(path, O_RDONLY | O_CLOEXEC)) == -1) return (errno); - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { - ret = errno; - goto error; - } if (fstat(fd, &st) == -1) { ret = errno; |