summaryrefslogtreecommitdiff
path: root/sbin/disklabel
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2016-05-28 16:46:45 +0000
committerBob Beck <beck@cvs.openbsd.org>2016-05-28 16:46:45 +0000
commit1d4aa42dfe8eb84b827fb84a53ec216bcb78f94a (patch)
treec88df64d89758a956389416f1c9adeb32b436ce8 /sbin/disklabel
parent8771dacd9bf6c0014b053ef08dd21ca26751ac07 (diff)
host readlabel() above the pledge so we can avoid pledge violations
when the provided device is not a disk ok tb@
Diffstat (limited to 'sbin/disklabel')
-rw-r--r--sbin/disklabel/disklabel.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c
index be0b76f59a1..6704594e650 100644
--- a/sbin/disklabel/disklabel.c
+++ b/sbin/disklabel/disklabel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disklabel.c,v 1.216 2016/05/28 16:00:19 beck Exp $ */
+/* $OpenBSD: disklabel.c,v 1.217 2016/05/28 16:46:44 beck Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -198,6 +198,7 @@ main(int argc, char *argv[])
&specname);
if (f < 0)
err(4, "%s", specname);
+ readlabel(f);
if (op == EDIT || op == EDITOR || aflag) {
if (pledge("stdio rpath wpath cpath disklabel proc exec", NULL) == -1)
@@ -221,19 +222,16 @@ main(int argc, char *argv[])
case EDIT:
if (argc != 1)
usage();
- readlabel(f);
error = edit(&lab, f);
break;
case EDITOR:
if (argc != 1)
usage();
- readlabel(f);
error = editor(f);
break;
case READ:
if (argc != 1)
usage();
- readlabel(f);
if (pledge("stdio", NULL) == -1)
err(1, "pledge");
@@ -247,7 +245,6 @@ main(int argc, char *argv[])
case RESTORE:
if (argc < 2 || argc > 3)
usage();
- readlabel(f);
if (!(t = fopen(argv[1], "r")))
err(4, "%s", argv[1]);
error = getasciilabel(t, &lab);
@@ -263,9 +260,7 @@ main(int argc, char *argv[])
fclose(t);
break;
case WRITE:
- if (dflag || aflag) {
- readlabel(f);
- } else if (argc < 2 || argc > 3)
+ if (!(dflag || aflag) && (argc < 2 || argc > 3))
usage();
else
makelabel(argv[1], argc == 3 ? argv[2] : NULL, &lab);