From 90381332e2063618431fa42cf5028870c5453cb4 Mon Sep 17 00:00:00 2001 From: Roland Lutz Date: Wed, 7 Jun 2017 20:11:43 +0200 Subject: iceprog: Check for invalid offset/size arguments --- iceprog/iceprog.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'iceprog') diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c index 8f93427..7886811 100644 --- a/iceprog/iceprog.c +++ b/iceprog/iceprog.c @@ -385,13 +385,21 @@ int main(int argc, char **argv) case 'R': read_mode = true; read_size = strtol(optarg, &endptr, 0); - if (!strcmp(endptr, "k")) read_size *= 1024; - if (!strcmp(endptr, "M")) read_size *= 1024 * 1024; + if (*endptr == '\0') /* ok */; + else if (!strcmp(endptr, "k")) read_size *= 1024; + else if (!strcmp(endptr, "M")) read_size *= 1024 * 1024; + else + errx(EXIT_FAILURE, + "`%s' is not a valid size", optarg); break; case 'o': rw_offset = strtol(optarg, &endptr, 0); - if (!strcmp(endptr, "k")) rw_offset *= 1024; - if (!strcmp(endptr, "M")) rw_offset *= 1024 * 1024; + if (*endptr == '\0') /* ok */; + else if (!strcmp(endptr, "k")) rw_offset *= 1024; + else if (!strcmp(endptr, "M")) rw_offset *= 1024 * 1024; + else + errx(EXIT_FAILURE, + "`%s' is not a valid offset", optarg); break; case 'c': check_mode = true; -- cgit v1.2.3