From owner-svn-src-head@FreeBSD.ORG Mon Dec 17 10:38:51 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id DFF799AA; Mon, 17 Dec 2012 10:38:51 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id C238C8FC15; Mon, 17 Dec 2012 10:38:51 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qBHAcpSJ069686; Mon, 17 Dec 2012 10:38:51 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qBHAcpN4069685; Mon, 17 Dec 2012 10:38:51 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201212171038.qBHAcpN4069685@svn.freebsd.org> From: Jilles Tjoelker Date: Mon, 17 Dec 2012 10:38:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r244350 - head/lib/libc/iconv X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Dec 2012 10:38:52 -0000 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;