Thanks for reporting the bug fix. The patch to glibc/posix/regexec.c looks good and I applied the attached patch to Gnulib's near-copy of that file. I did not review the proposed new test case for glibc.
From cd82caf3a0c3c9cc704ff69712b47da9581f8da0 Mon Sep 17 00:00:00 2001 From: Paul Eggert <[email protected]> Date: Tue, 10 Nov 2026 08:22:21 -0800 Subject: [PATCH] regex: fix return value on allocation failure Fix reported by Yuvraj Opawat in: https://sourceware.org/pipermail/libc-alpha/2026-November/181984.html * lib/regexec.c (check_matching): Return -2, not err, on error. --- ChangeLog | 7 +++++++ lib/regexec.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 858ab5d7dd..1de83b96ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2026-11-10 Paul Eggert <[email protected]> + + regex: fix return value on allocation failure + Fix reported by Yuvraj Opawat in: + https://sourceware.org/pipermail/libc-alpha/2026-November/181984.html + * lib/regexec.c (check_matching): Return -2, not err, on error. + 2026-11-09 Bruno Haible <[email protected]> doc: More motivation to use the string-desc module. diff --git a/lib/regexec.c b/lib/regexec.c index ff62ac08ef..370e71cceb 100644 --- a/lib/regexec.c +++ b/lib/regexec.c @@ -1144,13 +1144,13 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match, at_init_state = false; err = check_subexp_matching_top (mctx, &cur_state->nodes, 0); if (__glibc_unlikely (err != REG_NOERROR)) - return err; + return -2; if (cur_state->has_backref) { err = transit_state_bkref (mctx, &cur_state->nodes); if (__glibc_unlikely (err != REG_NOERROR)) - return err; + return -2; } } } -- 2.53.0
