mirror of
https://https.git.savannah.gnu.org/git/gnulib.git
synced 2026-04-28 06:33:36 +00:00
regex: avoid a UBSAN failure: remove an unnecessary DEBUG_ASSERT
* lib/regex_internal.c (re_node_set_insert): Remove the DEBUG_ASSERT and instead return early for an attempt to insert an ELEM that is already present in the set. Relax the function's comment that says there should be no duplicate. This function is called from many places and has been working fine. With its nontrivial backrefs, the sample regexp apparently elicits enough backtracking retries and state-set merges to trigger this duplicate insertion attempt. Reported by Bruno Haible in https://lists.gnu.org/r/bug-gnulib/2026-04/msg00138.html
This commit is contained in:
13
ChangeLog
13
ChangeLog
@@ -1,3 +1,16 @@
|
||||
2026-04-19 Jim Meyering <meyering@meta.com>
|
||||
|
||||
regex: avoid a UBSAN failure: remove an unnecessary DEBUG_ASSERT
|
||||
* lib/regex_internal.c (re_node_set_insert): Remove the DEBUG_ASSERT
|
||||
and instead return early for an attempt to insert an ELEM that is
|
||||
already present in the set. Relax the function's comment that says
|
||||
there should be no duplicate. This function is called from many
|
||||
places and has been working fine. With its nontrivial backrefs,
|
||||
the sample regexp apparently elicits enough backtracking retries
|
||||
and state-set merges to trigger this duplicate insertion attempt.
|
||||
Reported by Bruno Haible in
|
||||
https://lists.gnu.org/r/bug-gnulib/2026-04/msg00138.html
|
||||
|
||||
2026-04-19 Bruno Haible <bruno@clisp.org>
|
||||
|
||||
regex tests: Add a test case that triggers an assertion failure.
|
||||
|
||||
@@ -1241,8 +1241,8 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
|
||||
}
|
||||
|
||||
/* Insert the new element ELEM to the re_node_set* SET.
|
||||
SET should not already have ELEM.
|
||||
Return true if successful. */
|
||||
SET is not expected to already contain ELEM, but tolerate
|
||||
duplicates as a no-op. Return true if successful. */
|
||||
|
||||
static bool
|
||||
__attribute_warn_unused_result__
|
||||
@@ -1286,7 +1286,9 @@ re_node_set_insert (re_node_set *set, Idx elem)
|
||||
{
|
||||
for (idx = set->nelem; set->elems[idx - 1] > elem; idx--)
|
||||
set->elems[idx] = set->elems[idx - 1];
|
||||
DEBUG_ASSERT (set->elems[idx - 1] < elem);
|
||||
/* Already in set. Return early. */
|
||||
if (__glibc_unlikely (set->elems[idx - 1] == elem))
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Insert the new element. */
|
||||
|
||||
Reference in New Issue
Block a user