Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Jun 2012 08:35:47 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r237361 - stable/9/lib/libc/gen
Message-ID:  <201206210835.q5L8ZlBS099224@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Thu Jun 21 08:35:47 2012
New Revision: 237361
URL: http://svn.freebsd.org/changeset/base/237361

Log:
  MFC r237061:
  Make sure that fstab fd is not leaked on exec.
  
  PR:	kern/169023

Modified:
  stable/9/lib/libc/gen/fstab.c
Directory Properties:
  stable/9/lib/libc/   (props changed)

Modified: stable/9/lib/libc/gen/fstab.c
==============================================================================
--- stable/9/lib/libc/gen/fstab.c	Thu Jun 21 07:48:14 2012	(r237360)
+++ stable/9/lib/libc/gen/fstab.c	Thu Jun 21 08:35:47 2012	(r237361)
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/stat.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <fstab.h>
 #include <paths.h>
 #include <stdio.h>
@@ -246,6 +247,8 @@ getfsfile(name)
 int 
 setfsent()
 {
+	int fd;
+
 	if (_fs_fp) {
 		rewind(_fs_fp);
 		LineNo = 0;
@@ -257,11 +260,18 @@ setfsent()
 		else
 			setfstab(getenv("PATH_FSTAB"));
 	}
-	if ((_fs_fp = fopen(path_fstab, "r")) != NULL) {
+	fd = _open(path_fstab, O_RDONLY | O_CLOEXEC);
+	if (fd == -1) {
+		error(errno);
+		return (0);
+	}
+	_fs_fp = fdopen(fd, "r");
+	if (_fs_fp  != NULL) {
 		LineNo = 0;
 		return(1);
 	}
 	error(errno);
+	_close(fd);
 	return(0);
 }
 



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