Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Dec 2012 10:38:51 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r244350 - head/lib/libc/iconv
Message-ID:  <201212171038.qBHAcpN4069685@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201212171038.qBHAcpN4069685>