From: Willy Tarreau Date: Sat, 8 May 2021 04:50:28 +0000 (+0200) Subject: MINOR: sample: improve error reporting on missing arg to strcmp() converter X-Git-Tag: v2.4-dev19~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a1169b6231a03e61f253b5144ae8e604e20453b3;p=thirdparty%2Fhaproxy.git 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. --- 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;