Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/skeyinit Make sure using stdin/stdout/stderr is safe



details:   https://anonhg.NetBSD.org/src/rev/7851751280a3
branches:  trunk
changeset: 525999:7851751280a3
user:      itohy <itohy%NetBSD.org@localhost>
date:      Tue Apr 23 06:10:42 2002 +0000

description:
Make sure using stdin/stdout/stderr is safe
after opening any file.

diffstat:

 usr.bin/skeyinit/skeyinit.c |  13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diffs (34 lines):

diff -r 59fe48198b71 -r 7851751280a3 usr.bin/skeyinit/skeyinit.c
--- a/usr.bin/skeyinit/skeyinit.c       Tue Apr 23 05:56:44 2002 +0000
+++ b/usr.bin/skeyinit/skeyinit.c       Tue Apr 23 06:10:42 2002 +0000
@@ -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 @@
        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.");
 



Home | Main Index | Thread Index | Old Index