summaryrefslogtreecommitdiffstats
path: root/sbin/fdisk/misc.c
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2015-11-21 16:45:41 +0000
committerkrw <krw@openbsd.org>2015-11-21 16:45:41 +0000
commit684c15929ab3ac3abbbcdba77d2d06b5fd9f917c (patch)
tree620ff0920a7a6eff58d018de27eae7ec3eccfd51 /sbin/fdisk/misc.c
parentsync (diff)
downloadwireguard-openbsd-684c15929ab3ac3abbbcdba77d2d06b5fd9f917c.tar.xz
wireguard-openbsd-684c15929ab3ac3abbbcdba77d2d06b5fd9f917c.zip
Bring GPT partition editing into line with MBR partition editing
by presenting the existing offset and size as the defaults. Enhance getuint64() to take a minimum value as ask_num() does. Use this to ensure that GPT partitions are constrained to the valid area of the disk. Leave MBR partition constraints alone for the moment. Original problem(s) noted by tim@
Diffstat (limited to 'sbin/fdisk/misc.c')
-rw-r--r--sbin/fdisk/misc.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c
index 754128e47c6..0203b17a0d7 100644
--- a/sbin/fdisk/misc.c
+++ b/sbin/fdisk/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.58 2015/11/19 16:14:08 krw Exp $ */
+/* $OpenBSD: misc.c,v 1.59 2015/11/21 16:45:41 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -203,7 +203,7 @@ ask_yn(const char *str)
* adapted from sbin/disklabel/editor.c
*/
u_int64_t
-getuint64(char *prompt, u_int64_t oval, u_int64_t maxval)
+getuint64(char *prompt, u_int64_t oval, u_int64_t minval, u_int64_t maxval)
{
const int secsize = unit_types[SECTORS].conversion;
char buf[BUFSIZ], *endptr, *p, operator = '\0';
@@ -215,6 +215,8 @@ getuint64(char *prompt, u_int64_t oval, u_int64_t maxval)
if (oval > maxval)
oval = maxval;
+ if (oval < minval)
+ oval = minval;
secpercyl = disk.sectors * disk.heads;
@@ -304,7 +306,7 @@ getuint64(char *prompt, u_int64_t oval, u_int64_t maxval)
d2 = d;
}
- if (saveerr == ERANGE || d > maxval || d < 0 || d < d2) {
+ if (saveerr == ERANGE || d > maxval || d < minval || d < d2) {
printf("%s is out of range: %c%s%c\n", prompt, operator,
p, unit);
} else if (*endptr != '\0') {