[master] 63e4f71ef param: Clear least significant bits with none

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Tue Nov 21 06:03:09 UTC 2023


commit 63e4f71efb9392407863f87ca4a89127d252ecb0
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Nov 7 07:21:03 2023 +0100

    param: Clear least significant bits with none
    
    The most significant bits of the least significant octet would be
    omitted when the number of bits is not a multiple of eight.

diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c
index 6990f1b79..0c5301b83 100644
--- a/bin/varnishd/mgt/mgt_param_tweak.c
+++ b/bin/varnishd/mgt/mgt_param_tweak.c
@@ -607,6 +607,13 @@ bit(uint8_t *p, unsigned no, enum bit_do act)
 	return (*p & b);
 }
 
+static inline void
+bit_clear(uint8_t *p, unsigned l)
+{
+
+	memset(p, 0, (l + 7) >> 3);
+}
+
 /*--------------------------------------------------------------------
  */
 
@@ -665,14 +672,14 @@ tweak_generic_bits(struct vsb *vsb, const struct parspec *par, const char *arg,
 
 	if (arg != NULL && !strcmp(arg, "default") &&
 	    strcmp(par->def, "none")) {
-		memset(p, 0, l >> 3);
+		bit_clear(p, l);
 		return (tweak_generic_bits(vsb, par, par->def, p, l, tags,
 		    desc, sign));
 	}
 
 	if (arg != NULL && arg != JSON_FMT) {
 		if (sign == '+' && !strcmp(arg, "none"))
-			memset(p, 0, l >> 3);
+			bit_clear(p, l);
 		else
 			return (bit_tweak(vsb, p, l, arg, tags, desc, sign));
 	} else {
diff --git a/bin/varnishtest/tests/c00054.vtc b/bin/varnishtest/tests/c00054.vtc
index 420386b89..6730a6baa 100644
--- a/bin/varnishtest/tests/c00054.vtc
+++ b/bin/varnishtest/tests/c00054.vtc
@@ -1,13 +1,5 @@
 varnishtest "bitmap params masking"
 
-
-server s1 {
-	rxreq
-	txresp
-} -start
-
-varnish v1 -vcl+backend {} -start
-
 varnish v1 -cliok "param.show vsl_mask"
 varnish v1 -cliok "param.set vsl_mask -VCL_trace"
 varnish v1 -cliok "param.show vsl_mask"
@@ -15,6 +7,9 @@ varnish v1 -cliok "param.set vsl_mask -WorkThread,-TTL"
 varnish v1 -cliok "param.show vsl_mask"
 varnish v1 -cliok "param.set vsl_mask +WorkThread,+TTL,+Hash"
 varnish v1 -cliok "param.show vsl_mask"
+
+varnish v1 -cliexpect {"value": "none"} "param.set -j feature none"
+
 varnish v1 -clierr 106 "param.set vsl_mask FooBar"
 varnish v1 -clierr 106 "param.set vsl_mask -FooBar"
 varnish v1 -clierr 106 {param.set vsl_mask \"}
@@ -24,9 +19,3 @@ varnish v1 -cliok "param.show debug"
 varnish v1 -cliok "param.show feature"
 varnish v1 -cliok "param.set feature +short_panic"
 varnish v1 -cliok "param.show feature"
-
-
-client c1 {
-	txreq
-	rxresp
-} -run


More information about the varnish-commit mailing list