]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: make the param converter support control characters master
authorWilly Tarreau <w@1wt.eu>
Tue, 4 Aug 2026 09:04:06 +0000 (11:04 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 4 Aug 2026 09:10:14 +0000 (11:10 +0200)
Sometimes it can be convenient to support delimiting of the param()
converter using control characters that can be found in some request
bodies. Since the converter only supports a single character, we can
easily make an exception for "0xHH". That's what this patch does. The
reg-test was updated to include one 0x26.

doc/configuration.txt
reg-tests/converter/param.vtc
src/sample.c

index 7fa73bede4720654c3cecd2b567f7d4cc142db8b..545907a6ab7968c79eb4712048af2b114fbfdc78 100644 (file)
@@ -22587,7 +22587,12 @@ param(<name>[,<delim>])
   where parameters are delimited by <delim>, which defaults to "&", and the name
   and value of the parameter are separated by a "=". If there is no "=" and
   value before the end of the parameter segment, it is treated as equivalent to
-  a value of an empty string.
+  a value of an empty string. The delimiter must be either a single character,
+  or it can be the hexadecimal encoding of the delimiter's ASCII code in the
+  form "0xHH" (either upper or lower case). The hex form may sometimes be
+  needed to represent a NUL character or more generally control characters that
+  cannot be expressed in the configuration, and that can be found in request
+  bodies (see req.body).
 
   This can be useful for extracting parameters from a query string, or possibly
   a x-www-form-urlencoded body. In particular, `query,param(<name>)` can be used
index c33dc64eab5bea5fc615d5c33d0ce50b6f320888..d549b5baa2c6efc03759bca0a0d17ecc1f4c22c6 100644 (file)
@@ -24,7 +24,7 @@ haproxy h1 -conf {
 
        ### requests
        http-request set-var(txn.query) query
-       http-response set-header Found %[var(txn.query),param(test)] if { var(txn.query),param(test) -m found }
+       http-response set-header Found %[var(txn.query),param(test)] if { var(txn.query),param(test,0x26) -m found }
 
        default_backend be
 
index 5230db4a27284f2652f0317cb5bc00aefbd05256..d24225fe18794030fe6d783c0d65b8a4221217bd 100644 (file)
@@ -3213,8 +3213,22 @@ found:
 static int sample_conv_param_check(struct arg *arg, struct sample_conv *conv,
                                    const char *file, int line, char **err)
 {
+       if (arg[1].type == ARGT_STR && arg[1].data.str.data == 4 &&
+           strncmp(arg[1].data.str.area, "0x", 2) == 0) {
+               /* 0x can be decoded */
+               char *err = NULL;
+               int i = strtol(arg[1].data.str.area, &err, 0);
+
+               if (!err || !*err) {
+                       arg[1].data.str.area[0] = i;
+                       arg[1].data.str.data = 1;
+                       return 1;
+               }
+               /* otherwise fall back to the error message */
+       }
+
        if (arg[1].type == ARGT_STR && arg[1].data.str.data != 1) {
-               memprintf(err, "Delimiter must be exactly 1 character.");
+               memprintf(err, "Delimiter must be either exactly 1 character, or 0xHH for an ASCII code .");
                return 0;
        }