Make sure using stdin/stdout/stderr is safe

after opening any file.
This commit is contained in:
itohy 2002-04-23 06:10:42 +00:00
parent 8561815f09
commit f3e8a130b8
1 changed files with 12 additions and 1 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: skeyinit.c,v 1.16 2001/07/24 16:43:03 wiz Exp $ */
/* $NetBSD: skeyinit.c,v 1.17 2002/04/23 06:10:42 itohy Exp $ */
/* S/KEY v1.1b (skeyinit.c)
*
@ -22,6 +22,7 @@
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
@ -53,6 +54,16 @@ int main(int argc, char **argv)
struct tm *tm;
int c;
/*
* Make sure using stdin/stdout/stderr is safe
* after opening any file.
*/
i = open(_PATH_DEVNULL, O_RDWR);
while (i >= 0 && i < 2)
i = dup(i);
if (i > 2)
close(i);
if (geteuid() != 0)
errx(1, "must be setuid root.");