diff options
author | Alexander Hall <halex@cvs.openbsd.org> | 2009-07-24 23:28:01 +0000 |
---|---|---|
committer | Alexander Hall <halex@cvs.openbsd.org> | 2009-07-24 23:28:01 +0000 |
commit | 27ef2e128e225c798a000b7d050fe3733f9aa03c (patch) | |
tree | b9e9b980c57dc9fd532e006db763c7f0608fec13 /sbin/fdisk/misc.c | |
parent | 1745ecaa844f8c7691fa991d914864c9a6b6d1af (diff) |
properly sanitize the default value in ask_num(...)
Diffstat (limited to 'sbin/fdisk/misc.c')
-rw-r--r-- | sbin/fdisk/misc.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c index ae0ecaa2bc3..42420439c48 100644 --- a/sbin/fdisk/misc.c +++ b/sbin/fdisk/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.21 2009/04/07 16:06:37 weingart Exp $ */ +/* $OpenBSD: misc.c,v 1.22 2009/07/24 23:28:00 halex Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -96,18 +96,17 @@ ask_num(const char *str, int flags, int dflt, int low, int high, size_t lbuflen; int num; + if (dflt < low) + dflt = low; + else if (dflt > high) + dflt = high; + do { again: - if (dflt < low) - num = low; - else if (dflt > high) - num = high; - else - num = dflt; if (flags == ASK_HEX) - printf("%s [%X - %X]: [%X] ", str, low, high, num); + printf("%s [%X - %X]: [%X] ", str, low, high, dflt); else - printf("%s [%d - %d]: [%d] ", str, low, high, num); + printf("%s [%d - %d]: [%d] ", str, low, high, dflt); if (help) printf("(? for help) "); |