From ecb43693a904db8ebacf6eb8b6e1168f752f5d72 Mon Sep 17 00:00:00 2001 From: kib Date: Thu, 14 Jun 2012 12:28:43 +0000 Subject: Make sure that fstab fd is not leaked on exec. PR: kern/169023 Submitted by: Jukka Ukkonen MFC after: 1 week --- lib/libc/gen/fstab.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c index b2c28ad..882c57f 100644 --- a/lib/libc/gen/fstab.c +++ b/lib/libc/gen/fstab.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -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); } -- cgit v1.1