cxgbetool: Disallow negative values for numeric parameters.

Sponsored by:	Chelsio Communications
This commit is contained in:
Navdeep Parhar 2018-06-04 23:17:18 +00:00
parent fae7158959
commit a12a06fae2

View File

@ -606,31 +606,33 @@ static int
parse_val_mask(const char *param, const char *args[], uint32_t *val,
uint32_t *mask, int hashfilter)
{
long l;
char *p;
if (strcmp(param, args[0]) != 0)
return (EINVAL);
*val = strtoul(args[1], &p, 0);
if (p > args[1]) {
if (p[0] == 0) {
*mask = ~0;
return (0);
}
if (p[0] == ':' && p[1] != 0) {
if (hashfilter) {
warnx("param %s: mask not allowed for "
"hashfilter or nat params", param);
return (EINVAL);
}
*mask = strtoul(p+1, &p, 0);
if (p[0] == 0)
p = str_to_number(args[1], &l, NULL);
if (l >= 0 && l <= UINT32_MAX) {
*val = (uint32_t)l;
if (p > args[1]) {
if (p[0] == 0) {
*mask = ~0;
return (0);
} else {
warnx("param %s: mask not allowed for hashfilter",
param);
return (EINVAL);
}
if (p[0] == ':' && p[1] != 0) {
if (hashfilter) {
warnx("param %s: mask not allowed for "
"hashfilter or nat params", param);
return (EINVAL);
}
p = str_to_number(p + 1, &l, NULL);
if (l >= 0 && l <= UINT32_MAX && p[0] == 0) {
*mask = (uint32_t)l;
return (0);
}
}
}
}
@ -767,16 +769,19 @@ static int
parse_val(const char *param, const char *args[], uint32_t *val)
{
char *p;
long l;
if (strcmp(param, args[0]) != 0)
return (EINVAL);
*val = strtoul(args[1], &p, 0);
if (p > args[1] && p[0] == 0)
return (0);
p = str_to_number(args[1], &l, NULL);
if (*p || l < 0 || l > UINT32_MAX) {
warnx("parameter \"%s\" has bad \"value\" %s", args[0], args[1]);
return (EINVAL);
}
warnx("parameter \"%s\" has bad \"value\" %s", args[0], args[1]);
return (EINVAL);
*val = (uint32_t)l;
return (0);
}
static void