summaryrefslogtreecommitdiffstats
path: root/util/argconfig.c
diff options
context:
space:
mode:
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;