summaryrefslogtreecommitdiffstats
path: root/disk-utils/mkswap.c
diff options
context:
space:
mode:
authorKarel Zak2010-03-30 14:10:08 +0200
committerKarel Zak2010-03-30 14:45:37 +0200
commit20543e618a9d403259b4efb56145e94789814ea4 (patch)
treed06d2481814119a98aec08564aeb0ef79b66784f /disk-utils/mkswap.c
parentwipefs: support suffixes for --offset (diff)
downloadkernel-qcow2-util-linux-20543e618a9d403259b4efb56145e94789814ea4.tar.gz
kernel-qcow2-util-linux-20543e618a9d403259b4efb56145e94789814ea4.tar.xz
kernel-qcow2-util-linux-20543e618a9d403259b4efb56145e94789814ea4.zip
mkswap: more robust strtoull() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/mkswap.c')
-rw-r--r--disk-utils/mkswap.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index c19993752..bc6c1d291 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -559,13 +559,18 @@ main(int argc, char ** argv) {
usage();
}
if (block_count) {
- /* this silly user specified the number of blocks
- explicitly */
- char *tmp;
- int blocks_per_page = pagesize/1024;
- PAGES = strtoull(block_count,&tmp,0)/blocks_per_page;
- if (*tmp)
+ /* this silly user specified the number of blocks explicitly */
+ char *tmp = NULL;
+ long long blks;
+
+ errno = 0;
+ blks = strtoll(block_count, &tmp, 0);
+ if ((tmp && *tmp) ||
+ (errno != 0 && (blks == ULLONG_MAX || blks == 0)) ||
+ blks < 0)
usage();
+
+ PAGES = blks / (pagesize / 1024);
}
sz = get_size(device_name);
if (!PAGES) {