Skip to content

Commit

Permalink
regexec: Fix unintended return.
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
dag-erling committed Sep 10, 2024
1 parent bd8ca49 commit 0125d78
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/regexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0125d78

Please sign in to comment.