summaryrefslogtreecommitdiffstats
path: root/util/argconfig.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-07-02 20:47:46 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-07-02 20:47:46 +0000
commit5b7ddc4bd2dcdde201ffa2681ede9a0a029bad96 (patch)
tree352b477f97c1c36105310589c7568259c76e9385 /util/argconfig.c
parentAdding upstream version 1.12. (diff)
downloadnvme-cli-5b7ddc4bd2dcdde201ffa2681ede9a0a029bad96.tar.xz
nvme-cli-5b7ddc4bd2dcdde201ffa2681ede9a0a029bad96.zip
Adding upstream version 1.14.upstream/1.14
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'util/argconfig.c')
-rw-r--r--util/argconfig.c31
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;