summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2018-08-03 15:01:29 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2018-08-03 15:01:29 +0000
commitfb34fecf551492642fb8a3ee1800eaa0ca5553eb (patch)
treee241fad8bdf57d79848c252a1593307f2bb9a9ae
parent374bb9dce3e016966e571c2409a8d546b095cb56 (diff)
pledge() a little later, after getopt operation, in case -f option changes
the filename. We can then unveil that file, pledge() as before, and proceed to parsing.
-rw-r--r--usr.bin/last/last.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/usr.bin/last/last.c b/usr.bin/last/last.c
index b6f8f55fa5b..99f850222b3 100644
--- a/usr.bin/last/last.c
+++ b/usr.bin/last/last.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: last.c,v 1.50 2015/10/29 03:00:31 deraadt Exp $ */
+/* $OpenBSD: last.c,v 1.51 2018/08/03 15:01:28 deraadt Exp $ */
/* $NetBSD: last.c,v 1.6 1994/12/24 16:49:02 cgd Exp $ */
/*
@@ -98,9 +98,6 @@ main(int argc, char *argv[])
const char *errstr;
int ch, lastch = '\0', newarg = 1, prevoptind = 1;
- if (pledge("stdio rpath", NULL) == -1)
- err(1, "pledge");
-
while ((ch = getopt(argc, argv, "0123456789cf:h:n:st:d:T")) != -1) {
switch (ch) {
case '0': case '1': case '2': case '3': case '4':
@@ -155,6 +152,11 @@ main(int argc, char *argv[])
if (maxrec == 0)
exit(0);
+ if (unveil(file, "r") == -1)
+ err(1, "unveil");
+ if (pledge("stdio rpath", NULL) == -1)
+ err(1, "pledge");
+
if (argc) {
setvbuf(stdout, NULL, _IOLBF, 0);
for (argv += optind; *argv; ++argv) {