mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
Make sure that fstab fd is not leaked on exec.
PR: kern/169023 Submitted by: Jukka Ukkonen <jau iki fi> MFC after: 1 week
This commit is contained in:
parent
e474e51e07
commit
61235d9e01
1 changed files with 11 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue