From 8fcd44fade6023b0bc96ad211ba7c31ec7384858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Tue, 10 Sep 2024 07:47:21 +0200 Subject: [PATCH] regexec: Fix unintended return. In `tre_match()`, there is a spot where we check if the provided source is capable of rewinding, and return if it isn't. Due to missing braces, that return becomes unconditional when `TRE_USE_ALLOCA` is false. As a result, calling `regexec()` with a regex that includes back references always fails with `REG_BADPAT`. Fixes: 6f09108bb17c --- lib/regexec.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/regexec.c b/lib/regexec.c index b97b1ed..f5d8163 100644 --- a/lib/regexec.c +++ b/lib/regexec.c @@ -161,13 +161,15 @@ tre_match(const tre_tnfa_t *tnfa, const void *string, size_t len, { const tre_str_source *source = string; if (source->rewind == NULL || source->compare == NULL) - /* The backtracking matcher requires rewind and compare - capabilities from the input stream. */ + { + /* The backtracking matcher requires rewind and compare + capabilities from the input stream. */ #ifndef TRE_USE_ALLOCA - if (tags) - xfree(tags); + if (tags) + xfree(tags); #endif /* !TRE_USE_ALLOCA */ - return REG_BADPAT; + return REG_BADPAT; + } } status = tre_tnfa_run_backtrack(tnfa, string, (int)len, type, tags, eflags, &eo);