setuid(2): Suggest O_CLOEXEC instead of fcntl(F_SETFD).
This commit is contained in:
parent
844c2a3a94
commit
6b46581ed9
@ -28,7 +28,7 @@
|
|||||||
.\" @(#)setuid.2 8.1 (Berkeley) 6/4/93
|
.\" @(#)setuid.2 8.1 (Berkeley) 6/4/93
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd June 4, 1993
|
.Dd September 13, 2015
|
||||||
.Dt SETUID 2
|
.Dt SETUID 2
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -178,15 +178,10 @@ pseudocode(void)
|
|||||||
int fd;
|
int fd;
|
||||||
/* ... */
|
/* ... */
|
||||||
|
|
||||||
fd = open("/path/to/sensitive/data", O_RDWR);
|
fd = open("/path/to/sensitive/data", O_RDWR | O_CLOEXEC);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
err(1, "open");
|
err(1, "open");
|
||||||
|
|
||||||
/*
|
|
||||||
* Set close-on-exec flag; see fcntl(2) for more information.
|
|
||||||
*/
|
|
||||||
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
|
|
||||||
err(1, "fcntl(F_SETFD)");
|
|
||||||
/* ... */
|
/* ... */
|
||||||
execve(path, argv, environ);
|
execve(path, argv, environ);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user