From: Karel Zak Date: Tue, 30 Mar 2010 12:10:08 +0000 (+0200) Subject: mkswap: more robust strtoull() usage X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20543e618a9d403259b4efb56145e94789814ea4;p=util-linux mkswap: more robust strtoull() usage Signed-off-by: Karel Zak --- diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index c1999375..bc6c1d29 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) {