diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-07-02 20:49:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-07-02 20:49:35 +0000 |
commit | f2c543b4ccad3b9f8871d952cddf66b3b438595b (patch) | |
tree | c3c363d1cc72514221685c42a79a19b320114acc /util/argconfig.c | |
parent | Adding debian version 1.12-8. (diff) | |
download | nvme-cli-f2c543b4ccad3b9f8871d952cddf66b3b438595b.tar.xz nvme-cli-f2c543b4ccad3b9f8871d952cddf66b3b438595b.zip |
Merging upstream version 1.14.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'util/argconfig.c')
-rw-r--r-- | util/argconfig.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/util/argconfig.c b/util/argconfig.c index f647448..341a049 100644 --- a/util/argconfig.c +++ b/util/argconfig.c @@ -31,13 +31,14 @@ #include "argconfig.h" #include "suffix.h" -#include <string.h> +#include <errno.h> +#include <inttypes.h> #include <getopt.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> -#include <errno.h> #include <stdarg.h> -#include <inttypes.h> +#include <string.h> static argconfig_help_func *help_funcs[MAX_HELP_FUNC] = { NULL }; @@ -450,10 +451,11 @@ int argconfig_parse_subopt_string(char *string, char **options, return 0; } -unsigned argconfig_parse_comma_sep_array(char *string, int *val, +int argconfig_parse_comma_sep_array(char *string, int *val, unsigned max_length) { - unsigned ret = 0; + int ret = 0; + unsigned long v; char *tmp; char *p; @@ -464,9 +466,14 @@ unsigned argconfig_parse_comma_sep_array(char *string, int *val, if (!tmp) return 0; - val[ret] = strtol(tmp, &p, 0); + v = strtoul(tmp, &p, 0); if (*p != 0) return -1; + if (v > UINT_MAX) { + fprintf(stderr, "%s out of range\n", tmp); + return -1; + } + val[ret] = v; ret++; while (1) { @@ -478,19 +485,23 @@ unsigned argconfig_parse_comma_sep_array(char *string, int *val, if (ret >= max_length) return -1; - val[ret] = strtol(tmp, &p, 0); - + v = strtoul(tmp, &p, 0); if (*p != 0) return -1; + if (v > UINT_MAX) { + fprintf(stderr, "%s out of range\n", tmp); + return -1; + } + val[ret] = v; ret++; } } -unsigned argconfig_parse_comma_sep_array_long(char *string, +int argconfig_parse_comma_sep_array_long(char *string, unsigned long long *val, unsigned max_length) { - unsigned ret = 0; + int ret = 0; char *tmp; char *p; |