summaryrefslogtreecommitdiff
path: root/usr.bin/fstat
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2002-08-04 00:48:35 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2002-08-04 00:48:35 +0000
commit02f37d2c33698e7de6a382aac3dcdf42275e059d (patch)
treec77ba901d9fa949109f8453f1a9958a172902960 /usr.bin/fstat
parenta917ae9e72545a050b91b403fba7a52764ad8b90 (diff)
move kvm opening to earliest possible place
Diffstat (limited to 'usr.bin/fstat')
-rw-r--r--usr.bin/fstat/fstat.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
index a30de10de47..5497e733d6f 100644
--- a/usr.bin/fstat/fstat.c
+++ b/usr.bin/fstat/fstat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fstat.c,v 1.40 2002/07/13 06:02:57 deraadt Exp $ */
+/* $OpenBSD: fstat.c,v 1.41 2002/08/04 00:48:34 deraadt Exp $ */
/*-
* Copyright (c) 1988, 1993
@@ -41,7 +41,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)fstat.c 8.1 (Berkeley) 6/6/93";*/
-static char *rcsid = "$OpenBSD: fstat.c,v 1.40 2002/07/13 06:02:57 deraadt Exp $";
+static char *rcsid = "$OpenBSD: fstat.c,v 1.41 2002/08/04 00:48:34 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -225,6 +225,21 @@ main(int argc, char *argv[])
usage();
}
+ /*
+ * Discard setgid privileges if not the running kernel so that bad
+ * guys can't print interesting stuff from kernel memory.
+ */
+ if (nlistf != NULL || memf != NULL) {
+ setegid(getgid());
+ setgid(getgid());
+ }
+
+ if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL)
+ errx(1, "%s", buf);
+
+ setegid(getgid());
+ setgid(getgid());
+
if (*(argv += optind)) {
for (; *argv; ++argv) {
if (getfname(*argv))
@@ -243,21 +258,6 @@ main(int argc, char *argv[])
checkfile = 1;
}
- /*
- * Discard setgid privileges if not the running kernel so that bad
- * guys can't print interesting stuff from kernel memory.
- */
- if (nlistf != NULL || memf != NULL) {
- setegid(getgid());
- setgid(getgid());
- }
-
- if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL)
- errx(1, "%s", buf);
-
- setegid(getgid());
- setgid(getgid());
-
if ((p = kvm_getprocs(kd, what, arg, &cnt)) == NULL)
errx(1, "%s", kvm_geterr(kd));
if (nflg)