]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: stream: Avoid recursive evaluation for unique-id based on itself
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 23 Jun 2025 05:33:06 +0000 (07:33 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 24 Jun 2025 06:04:50 +0000 (08:04 +0200)
There is nothing that prevent a "unique-id-format" to reference itself,
using '%ID' or '%[unique-id]'. If the sample fetch function is used, it
leads to an infinite loop, calling recursively the function responsible to
generate the unique ID.

One solution is to detect it during the configuration parsing to trigger an
error. With this patch, we just inhibit recursive calls by considering the
unique-id as empty during its evaluation. So "id-%[unique-id]" lf string
will be evaluated as "id-".

This patch must be backported to all stable versions.

src/stream.c

index 005b49eeaa001bcf07cb9c64dc7f1aff20e9c108..019d252f9e885c9ba65b44a85363a2de89bf4fd4 100644 (file)
@@ -2942,12 +2942,12 @@ struct ist stream_generate_unique_id(struct stream *strm, struct lf_expr *format
        }
        else {
                char *unique_id;
-               int length;
+
                if ((unique_id = pool_alloc(pool_head_uniqueid)) == NULL)
                        return IST_NULL;
 
-               length = build_logline(strm, unique_id, UNIQUEID_LEN, format);
-               strm->unique_id = ist2(unique_id, length);
+               strm->unique_id = ist2(unique_id, 0);
+               strm->unique_id.len = build_logline(strm, unique_id, UNIQUEID_LEN, format);
 
                return strm->unique_id;
        }