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
This commit is contained in:
parent
790ffa6cfd
commit
571d9493ad
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user