From a1169b6231a03e61f253b5144ae8e604e20453b3 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 8 May 2021 06:50:28 +0200 Subject: [PATCH] MINOR: sample: improve error reporting on missing arg to strcmp() converter 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 : 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 : invalid args in converter 'strcmp' : missing variable name. This was done for secure_strcmp() as well. --- src/sample.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/sample.c b/src/sample.c index b48cf71c27..510d6b5045 100644 --- a/src/sample.c +++ b/src/sample.c @@ -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; -- 2.47.2