]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: improve error reporting on missing arg to strcmp() converter
authorWilly Tarreau <w@1wt.eu>
Sat, 8 May 2021 04:50:28 +0000 (06:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 8 May 2021 04:55:25 +0000 (06:55 +0200)
Calling the strcmp() converter with no argument yields this strange error:

  [ALERT]    (31439) : parsing [test.cfg:3] : error detected in frontend 'f' while parsing 'http-request redirect' rule : failed to parse sample expression <src,strcmp]> : invalid args in converter 'strcmp' : failed to register variable name ''.

This is because the vars name check tries to see if it can create such a
variable having an empty name. Let's at least make a special case of the
missing argument. Now we can read a more explicit:

  [ALERT]    (31655) : parsing [test.cfg:3] : error detected in frontend 'f' while parsing 'http-request redirect' rule : failed to parse sample expression <src,strcmp]> : invalid args in converter 'strcmp' : missing variable name.

This was done for secure_strcmp() as well.

src/sample.c

index b48cf71c27c29b0742c9a14359e0d5cc02dcf4c7..510d6b5045e8defe59da98efbacea2ab69833864 100644 (file)
@@ -3591,6 +3591,11 @@ static int sample_conv_mqtt_is_valid(const struct arg *arg_p, struct sample *smp
 static int smp_check_strcmp(struct arg *args, struct sample_conv *conv,
                            const char *file, int line, char **err)
 {
+       if (!args[0].data.str.data) {
+               memprintf(err, "missing variable name");
+               return 0;
+       }
+
        /* Try to decode a variable. */
        if (vars_check_arg(&args[0], NULL))
                return 1;
@@ -3607,6 +3612,11 @@ static int smp_check_strcmp(struct arg *args, struct sample_conv *conv,
 static int smp_check_secure_memcmp(struct arg *args, struct sample_conv *conv,
                            const char *file, int line, char **err)
 {
+       if (!args[0].data.str.data) {
+               memprintf(err, "missing variable name");
+               return 0;
+       }
+
        /* Try to decode a variable. */
        if (vars_check_arg(&args[0], NULL))
                return 1;