From: Willy Tarreau Date: Sat, 21 Nov 2026 07:59:56 +0000 (+0100) Subject: BUG/MEDIUM: pattern: check for non-empty string before matching regexes X-Git-Url: https://git.kaiwu.me/http/%7Bsubstring-before(@doc,%20'.xml')%7D.html?a=commitdiff_plain;h=4b348d2a4d528d98b5bb6d925d26e569a4b9509e;p=haproxy.git BUG/MEDIUM: pattern: check for non-empty string before matching regexes Zübeyir Eser reported in github issue #3602 that passing req.body to the default regex engine crashes when there is no body. This is because the body returns an empty sample while the default regex engine demands at least one byte available to write a trailing zero. Let's make sure that regex matches don't even run when subject to empty strings. This can be backported to all branches. --- diff --git a/src/pattern.c b/src/pattern.c index 8322a71b1..1c61b32c8 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -608,6 +608,9 @@ struct pattern *pat_match_regm(struct sample *smp, struct pattern_expr *expr, in struct pattern *pattern; struct pattern *ret = NULL; + if (!smp->data.u.str.data) + return ret; + list_for_each_entry(lst, &expr->patterns, list) { pattern = &lst->pat; @@ -634,6 +637,9 @@ struct pattern *pat_match_reg(struct sample *smp, struct pattern_expr *expr, int struct pattern *ret = NULL; struct lru64 *lru = NULL; + if (!smp->data.u.str.data) + return ret; + if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 5) { unsigned long long seed = pat_lru_seed ^ (long)expr;