Commit 34e161f9 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

param: Deny extra input after a double

By themselves, structured fields parsing functions don't fail on extra
input. To avoid repeating the same checks twice, they are wrapped into a
function that will help generalize tweak_generic_double() at least once
more.
parent b34774ee
......@@ -52,34 +52,44 @@ const char * const JSON_FMT = (const char *)&JSON_FMT;
* Generic handling of double typed parameters
*/
static double
parse_decimal(const char *p, const char **err)
{
double v;
v = SF_Parse_Decimal(&p, 0, err);
if (errno == 0 && *p != '\0') {
errno = EINVAL;
*err = "Invalid number";
}
return (v);
}
static int
tweak_generic_double(struct vsb *vsb, const char *arg, const struct parspec *pp,
const char *fmt)
{
volatile double u, minv = VRT_DECIMAL_MIN, maxv = VRT_DECIMAL_MAX;
volatile double *dest = pp->priv;
const char *p, *err;
const char *err;
if (arg != NULL && arg != JSON_FMT) {
if (pp->min != NULL) {
p = pp->min;
minv = SF_Parse_Decimal(&p, 0, &err);
minv = parse_decimal(pp->min, &err);
if (errno) {
VSB_printf(vsb, "Min: %s (%s)\n", err, pp->min);
return (-1);
}
}
if (pp->max != NULL) {
p = pp->max;
maxv = SF_Parse_Decimal(&p, 0, &err);
maxv = parse_decimal(pp->max, &err);
if (errno) {
VSB_printf(vsb, "Max: %s (%s)\n", err, pp->max);
return (-1);
}
}
p = arg;
u = SF_Parse_Decimal(&p, 0, &err);
u = parse_decimal(arg, &err);
if (errno) {
VSB_printf(vsb, "%s (%s)\n", err, arg);
return (-1);
......
......@@ -4,6 +4,7 @@ varnish v1 -vcl {backend be none;} -start
varnish v1 -clierr 106 "param.set default_ttl -1"
varnish v1 -clierr 106 {param.set acceptor_sleep_decay "0.42 is not a number"}
varnish v1 -clierr 106 "param.set acceptor_sleep_max 20"
varnish v1 -cliok "param.set prefer_ipv6 off"
varnish v1 -cliok "param.set prefer_ipv6 no"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment