From e5066a307b62b7b64c91add8131d94aef3cfcf42 Mon Sep 17 00:00:00 2001 From: J08nY Date: Thu, 28 Jun 2018 17:03:11 +0200 Subject: Add check that bits in argument are indeed a number. --- src/io/cli.c | 6 +++++- test/ecgen.sh | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/io/cli.c b/src/io/cli.c index 2ca4b29..14d51f8 100644 --- a/src/io/cli.c +++ b/src/io/cli.c @@ -380,7 +380,11 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) { argp_usage(state); } - cfg->bits = strtoul(arg, NULL, 10); + char *bits_end = NULL; + cfg->bits = strtoul(arg, &bits_end, 10); + if (*bits_end != '\0') { + argp_failure(state, 1, 0, "Invalid bit size specified."); + } cfg->hex_digits = 2 * (cfg->bits / 8 + (cfg->bits % 8 != 0 ? 1 : 0)); break; diff --git a/test/ecgen.sh b/test/ecgen.sh index c8f1d96..2378abd 100755 --- a/test/ecgen.sh +++ b/test/ecgen.sh @@ -129,6 +129,7 @@ function cli() { assert_raises "${ecgen} --brainpool-rfc=01234 --fp 10" 1 assert_raises "${ecgen} --ansi=01234 --fp 10" 1 assert_raises "${ecgen} --hex-check=not_hex --fp 10" 1 + assert_raises "${ecgen} abc" 1 } function hex() { -- cgit v1.2.3-70-g09d2