From: Aurelien DARRAGON Date: Thu, 25 Apr 2024 07:50:14 +0000 (+0200) Subject: MINOR: log: skip custom logformat_node name if empty X-Git-Tag: v3.0-dev9~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d3c92a3a830c6909cc3784f879dace9627ce23e9;p=thirdparty%2Fhaproxy.git MINOR: log: skip custom logformat_node name if empty Reminder: Since 3.0-dev4, we can optionally give a name to logformat nodes: log-format "%(custom_name1)B %(custom_name2)[str(value)]" But we may also optionally set the expected node type by appending ':type' after the name, type being either sint,str or bool, like this: log-format "%(string_as_int:sint)[str(14)]" However, it is currently not possible to provide a type without providing a name that is a least 1 char long. But it could be useful to provide a type without setting a name, like this, for typecasting purposes only: log-format "%(:sint)[bool(true)]" Thus in order to allow this usage, don't set node->name if node name is not at least 1 character long. By doing so, node->name will remain NULL and will not be considered, but the typecast setting will. --- diff --git a/src/log.c b/src/log.c index 4abe30c969..32da3f706c 100644 --- a/src/log.c +++ b/src/log.c @@ -421,7 +421,7 @@ static int parse_logformat_tag(char *arg, int arg_len, char *name, int name_len, node->type = LOG_FMT_TAG; node->tag = &logformat_tags[j]; node->typecast = typecast; - if (name) + if (name && name_len) node->name = my_strndup(name, name_len); node->options = lf_expr->nodes.options; if (arg_len) { @@ -523,7 +523,7 @@ static int add_sample_to_logformat_list(char *text, char *name, int name_len, in memprintf(err, "out of memory error"); goto error_free; } - if (name) + if (name && name_len) node->name = my_strndup(name, name_len); node->type = LOG_FMT_EXPR; node->typecast = typecast;