diff options
author | Alexander Hall <halex@cvs.openbsd.org> | 2010-07-02 02:54:10 +0000 |
---|---|---|
committer | Alexander Hall <halex@cvs.openbsd.org> | 2010-07-02 02:54:10 +0000 |
commit | 506e5b6520a929b003eaa3dba4990856e0fd2dfd (patch) | |
tree | ed8c2a930ca60c6622939ee0db59127847671101 | |
parent | 5199f65787421ebb56e123e8954ceb6d55a61b24 (diff) |
on error, getuint() will return UINT_MAX. Instead of actually using
that value, print an error message and repost the question
ok krw@ deraadt@
-rw-r--r-- | sbin/fdisk/cmd.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index 3bde6abdae1..2708b13759c 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.44 2009/12/24 10:06:35 sobrado Exp $ */ +/* $OpenBSD: cmd.c,v 1.45 2010/07/02 02:54:09 halex Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -35,6 +35,7 @@ #include <signal.h> #include <sys/fcntl.h> #include <sys/disklabel.h> +#include <limits.h> #include "disk.h" #include "misc.h" #include "user.h" @@ -199,22 +200,33 @@ Xedit(cmd_t *cmd, disk_t *disk, mbr_t *mbr, mbr_t *tt, int offset) PRT_fix_CHS(disk, pp); } else { u_int m; + u_int32_t d; /* Get data */ - pp->bs = getuint(disk, "offset", - "Starting sector for this partition.", pp->bs, - disk->real->size, 0, DO_CONVERSIONS | - (pp->id == FS_BSDFFS ? DO_ROUNDING : 0)); + d = pp->bs; + do { + pp->bs = getuint(disk, "offset", + "Starting sector for this partition.", d, + disk->real->size, 0, DO_CONVERSIONS | + (pp->id == FS_BSDFFS ? DO_ROUNDING : 0)); + if (pp->bs == UINT_MAX) + printf("Invalid offset.\n"); + } while (pp->bs == UINT_MAX); m = MAX(pp->ns, disk->real->size - pp->bs); if ( m > disk->real->size - pp->bs) { /* dont have default value extend beyond end of disk */ m = disk->real->size - pp->bs; } - pp->ns = getuint(disk, "size", "Size of the partition.", - pp->ns, m, pp->bs , DO_CONVERSIONS | - ((pp->id == FS_BSDFFS || pp->id == FS_SWAP) ? - DO_ROUNDING : 0)); + d = pp->ns; + do { + pp->ns = getuint(disk, "size", "Size of the partition.", + d, m, pp->bs , DO_CONVERSIONS | + ((pp->id == FS_BSDFFS || pp->id == FS_SWAP) ? + DO_ROUNDING : 0)); + if (pp->ns == UINT_MAX) + printf("Invalid size.\n"); + } while (pp->ns == UINT_MAX); /* Fix up CHS values */ PRT_fix_CHS(disk, pp); |