[master] 34e161f94 param: Deny extra input after a double
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Tue May 24 15:49:06 UTC 2022
commit 34e161f948d6e627ffed06752ec8dd4a8ce2e800
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Thu Dec 30 06:21:53 2021 +0100
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.
diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c
index e6e7aaedd..ea6e935d9 100644
--- a/bin/varnishd/mgt/mgt_param_tweak.c
+++ b/bin/varnishd/mgt/mgt_param_tweak.c
@@ -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);
diff --git a/bin/varnishtest/tests/b00042.vtc b/bin/varnishtest/tests/b00042.vtc
index 037469ec7..cda710935 100644
--- a/bin/varnishtest/tests/b00042.vtc
+++ b/bin/varnishtest/tests/b00042.vtc
@@ -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"
More information about the varnish-commit
mailing list