Author: jilles
Date: Mon Dec 17 10:38:51 2012
New Revision: 244350
URL: http://svnweb.freebsd.org/changeset/base/244350

Log:
  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

Modified:
  head/lib/libc/iconv/citrus_mmap.c

Modified: head/lib/libc/iconv/citrus_mmap.c
==============================================================================
--- head/lib/libc/iconv/citrus_mmap.c   Mon Dec 17 10:23:22 2012        
(r244349)
+++ head/lib/libc/iconv/citrus_mmap.c   Mon Dec 17 10:38:51 2012        
(r244350)
@@ -57,12 +57,8 @@ _citrus_map_file(struct _citrus_region *
 
        _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;
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to