>From b98042a11694ad5dd94f4d5d0110ddce833aeac0 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 29 Nov 2026 18:32:51 +0000 Subject: [PATCH] regex: fix missing alloc failure checks in regcomp on oom regcomp could crash with null deref or in some cases continue and succeed with an incorrect parse tree, but the latter is unlikely in practice: there are followup allocations that would fail too and return the right error code. Reported-by: Georg Meyer --- src/regex/regcomp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c index b4b81968..af29cab8 100644 --- a/src/regex/regcomp.c +++ b/src/regex/regcomp.c @@ -1045,6 +1045,8 @@ static reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) } nbranch = tre_ast_new_catenation(ctx->mem, nbranch, ctx->n); + if (!nbranch) + return REG_ESPACE; if ((ere && *s == '|') || (ere && *s == ')' && depth) || (!ere && *s == '\\' && s[1] == ')') || @@ -1055,6 +1057,8 @@ static reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) here they are not rejected but match on empty string */ int c = *s; nunion = tre_ast_new_union(ctx->mem, nunion, nbranch); + if (!nunion) + return REG_ESPACE; nbranch = 0; if (c == '\\' && s[1] == '|') { -- 2.52.0