]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: pattern: check for non-empty string before matching regexes
authorWilly Tarreau <w@1wt.eu>
Sat, 21 Nov 2026 07:59:56 +0000 (08:59 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 21 Nov 2026 07:59:56 +0000 (08:59 +0100)
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.

src/pattern.c

index 8322a71b153d4fa71a86d77e3f9d5d4a3aa4a8af..1c61b32c8144c75b117970c85f5a98fa5235a0e9 100644 (file)
@@ -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;