Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package glibc for openSUSE:Factory checked in at 2026-11-27 19:40:05 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/glibc (Old) and /work/SRC/openSUSE:Factory/.glibc.new.1340718 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "glibc" Fri Nov 27 19:40:05 2026 rev:311 rq:1400836 version:2.44 Changes: -------- --- /work/SRC/openSUSE:Factory/glibc/glibc.changes 2026-11-13 18:25:01.967139400 +0100 +++ /work/SRC/openSUSE:Factory/.glibc.new.1340718/glibc.changes 2026-11-27 19:40:07.324516143 +0100 @@ -1,0 +2,13 @@ +Mon Nov 16 13:49:43 UTC 2026 - Andreas Schwab <[email protected]> + +- regex-alloc-fail-double-free.patch: posix: Fix double free after + allocation failure in regcomp and regexec (CVE-2026-100290, bsc#1290239, + BZ #34991) +- wide-scanf-double-null.patch: stdio-common: Fix double null terminator + in wide scanf %s and %[ (CVE-2026-115819, bsc#1290240, BZ #34989) +- iso-2022-cn-ext-so-handling.patch: iconv: ISO-2022-CN-EXT: fix SO + handling without a designation (CVE-2026-121758, bsc#1290813, BZ #34774) +- ibm139x-read-input-bounds.patch: IBM1390/IBM1399 encoders read past + input bounds (CVE-2026-124024, bsc#1290815, BZ #34914) + +------------------------------------------------------------------- New: ---- ibm139x-read-input-bounds.patch iso-2022-cn-ext-so-handling.patch regex-alloc-fail-double-free.patch wide-scanf-double-null.patch ----------(New B)---------- New: handling without a designation (CVE-2026-121758, bsc#1290813, BZ #34774) - ibm139x-read-input-bounds.patch: IBM1390/IBM1399 encoders read past input bounds (CVE-2026-124024, bsc#1290815, BZ #34914) New: in wide scanf %s and %[ (CVE-2026-115819, bsc#1290240, BZ #34989) - iso-2022-cn-ext-so-handling.patch: iconv: ISO-2022-CN-EXT: fix SO handling without a designation (CVE-2026-121758, bsc#1290813, BZ #34774) New: - regex-alloc-fail-double-free.patch: posix: Fix double free after allocation failure in regcomp and regexec (CVE-2026-100290, bsc#1290239, New: BZ #34991) - wide-scanf-double-null.patch: stdio-common: Fix double null terminator in wide scanf %s and %[ (CVE-2026-115819, bsc#1290240, BZ #34989) ----------(New E)---------- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ glibc.spec ++++++ --- /var/tmp/diff_new_pack.99S5HS/_old 2026-11-27 19:40:09.910621820 +0100 +++ /var/tmp/diff_new_pack.99S5HS/_new 2026-11-27 19:40:09.915622024 +0100 @@ -371,6 +371,14 @@ Patch1021: realloc-mmap-non-mremap.patch # PATCH-FIX-UPSTREAM intl: Restrict path traversal when using LANGUAGE env var (CVE-2026-84243, BZ #17142) Patch1022: intl-restrict-path-traversal.patch +# PATCH-FIX-UPSTREAM posix: Fix double free after allocation failure in regcomp and regexec (CVE-2026-100290, BZ #34991) +Patch1023: regex-alloc-fail-double-free.patch +# PATCH-FIX-UPSTREAM stdio-common: Fix double null terminator in wide scanf %%s and %%[ (CVE-2026-115819, BZ #34989) +Patch1024: wide-scanf-double-null.patch +# PATCH-FIX-UPSTREAM iconv: ISO-2022-CN-EXT: fix SO handling without a designation (CVE-2026-121758, BZ #34774) +Patch1025: iso-2022-cn-ext-so-handling.patch +# PATCH-FIX-UPSTREAM IBM1390/IBM1399 encoders read past input bounds (CVE-2026-124024, BZ #34914) +Patch1026: ibm139x-read-input-bounds.patch %endif ### ++++++ ibm139x-read-input-bounds.patch ++++++ >From 77fe280828e85ac329e5644e8546440e9c1b0453 Mon Sep 17 00:00:00 2001 From: Andreas Schwab <[email protected]> Date: Thu, 12 Nov 2026 15:31:07 +0100 Subject: [PATCH] iconvdata: IBM1390/IBM1399 encoders read past input bounds (bug 34914) Fix a bounds check when the IBM1390 and IBM1399 encoders look up the next character after a combining base. --- iconvdata/Makefile | 3 ++ iconvdata/ibm1364.c | 2 +- iconvdata/tst-iconv-ibm1390.c | 65 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 iconvdata/tst-iconv-ibm1390.c diff --git a/iconvdata/Makefile b/iconvdata/Makefile index 8d12308c94..2abafa8b0a 100644 --- a/iconvdata/Makefile +++ b/iconvdata/Makefile @@ -89,7 +89,7 @@ tests = \ tst-iconv6 bug-iconv5 bug-iconv6 tst-iconv7 bug-iconv8 bug-iconv9 \ bug-iconv10 bug-iconv11 bug-iconv12 tst-iconv-big5-hkscs-to-2ucs4 \ bug-iconv13 bug-iconv14 bug-iconv15 \ - tst-iconv-iso-2022-cn-ext tst-bug33980 + tst-iconv-iso-2022-cn-ext tst-bug33980 tst-iconv-ibm1390 ifeq ($(have-thread-library),yes) tests += bug-iconv3 endif @@ -356,6 +357,8 @@ $(objpfx)tst-bug33980.out: $(addprefix $(objpfx), $(gconv-modules)) \ $(addprefix $(objpfx),$(modules.so)) $(objpfx)tst-bug33980.out: $(addprefix $(objpfx), $(gconv-modules)) \ $(addprefix $(objpfx),$(modules.so)) +$(objpfx)tst-iconv-ibm1390.out: $(addprefix $(objpfx), $(gconv-modules)) \ + $(addprefix $(objpfx),$(modules.so)) $(objpfx)iconv-test.out: run-iconv-test.sh \ $(addprefix $(objpfx), $(gconv-modules)) \ diff --git a/iconvdata/ibm1364.c b/iconvdata/ibm1364.c index 8df66ea048..6b99d3b06d 100644 --- a/iconvdata/ibm1364.c +++ b/iconvdata/ibm1364.c @@ -286,7 +286,7 @@ enum while (cmbp->res1 < ch) \ ++cmbp; \ /* XXX if last char is beginning of combining store in state */ \ - if (cmbp->res1 == ch && inptr + 4 < inend) \ + if (cmbp->res1 == ch && inend - inptr >= 8) \ { \ /* See if input is part of a combined character. */ \ uint32_t ch_next = get32 (inptr + 4); \ diff --git a/iconvdata/tst-iconv-ibm1390.c b/iconvdata/tst-iconv-ibm1390.c new file mode 100644 index 0000000000..939588df0a --- /dev/null +++ b/iconvdata/tst-iconv-ibm1390.c @@ -0,0 +1,65 @@ +/* Verify IBM1390/IBM1399 do not read past the input bounds. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <string.h> +#include <errno.h> +#include <iconv.h> + +#include <support/check.h> +#include <support/next_to_fault.h> +#include <support/support.h> + +static void +test_ibm139x (const char *coding) +{ + /* Use WCHAR_T as input encoding so that the encoder reads directly from + the input buffer. */ + iconv_t cd = iconv_open (coding, "WCHAR_T"); + TEST_VERIFY_EXIT (cd != (iconv_t) -1); + + /* Place a combining base one byte before the end of the buffer, to + check that the encoder does not read past the end of it. */ + struct support_next_to_fault ntf = support_next_to_fault_allocate (9); + memcpy (ntf.buffer, L"a\x00E6", 8); + ntf.buffer[8] = 0; + + char *inp = ntf.buffer; + size_t inleft = 9; + + char outbuf[32]; + char *outp = outbuf; + size_t outleft = sizeof (outbuf); + + TEST_COMPARE (iconv (cd, &inp, &inleft, &outp, &outleft), (size_t) -1); + TEST_COMPARE (errno, EINVAL); + TEST_COMPARE (inleft, 1); + TEST_VERIFY (inp == ntf.buffer + 8); + TEST_COMPARE (iconv_close (cd), 0); + support_next_to_fault_free (&ntf); +} + +static int +do_test (void) +{ + test_ibm139x ("IBM1390"); + test_ibm139x ("IBM1399"); + + return 0; +} + +#include <support/test-driver.c> -- 2.56.1 ++++++ iso-2022-cn-ext-so-handling.patch ++++++ >From 625054f30f0e7a961519f045f2364aa3ca6c1c6b Mon Sep 17 00:00:00 2001 From: JT Wang <[email protected]> Date: Thu, 12 Nov 2026 05:08:42 +0000 Subject: [PATCH] iconv: ISO-2022-CN-EXT: fix SO handling without a designation (bug 34774) In the FROM loop, the SO (0x0e) handler advances inptr before checking whether an SO designation had been announced. Without a designation the SO byte is an error, but by the time the error is reported the byte has already been consumed. Consequences: * With //IGNORE, STANDARD_FROM_LOOP_ERR_HANDLER skips one more byte after the already-consumed SO. If the SO is the last input byte, inptr ends up one past inend; the loop condition inptr != inend then no longer terminates the loop, and the converter keeps reading past the end of the input buffer and may convert out-of-bounds bytes into the output, in addition to the *inbytesleft wraparound described in the report. This is also the path taken by iconv -c, which sets the ignore flag for the conversion. If the SO is not the last byte, the byte following it is silently dropped. * Without //IGNORE there is no out-of-bounds access, but iconv() returns EILSEQ with the SO already consumed, so *inbuf does not point at the offending byte and the reported remaining length is one byte short (or exhausted when the SO is the last byte). A caller that skips the offending byte on EILSEQ and calls iconv() again then decrements an already-exhausted length. Move the increment after the error handler: the ignore path skips the SO exactly once, and the non-ignore path leaves the input pointer on the SO byte as POSIX expects. Sequences with an announced designation are unaffected. Also update the stale comment in that branch, and extend tst-iconv-iso-2022-cn-ext with FROM-direction regressions covering the error paths, a trailing SO with //IGNORE placed next to an inaccessible page, and a designated-SO positive case. Signed-off-by: JT Wang <[email protected]> Reviewed-by: Adhemerval Zanella <[email protected]> (cherry picked from commit 170ee485fa89b95c3bb7d5606c9812c6c100c9be) --- NEWS | 3 + iconvdata/iso-2022-cn-ext.c | 10 +- iconvdata/tst-iconv-iso-2022-cn-ext.c | 180 ++++++++++++++++++++++++++ 3 files changed, 187 insertions(+), 6 deletions(-) diff --git a/iconvdata/iso-2022-cn-ext.c b/iconvdata/iso-2022-cn-ext.c index d0b1083fba..cc8349a050 100644 --- a/iconvdata/iso-2022-cn-ext.c +++ b/iconvdata/iso-2022-cn-ext.c @@ -248,12 +248,9 @@ enum } \ else if (ch == SO) \ { \ - /* Switch to use GB2312, GB12345, CNS 11643 plane 1, or ISO-IR-165, \ - depending on which S0 designation came last. The only problem \ - is what to do with faulty input files where no designator came. \ - XXX For now I'll default to use GB2312. If this is not the \ - best behavior (e.g., we should flag an error) let me know. */ \ - ++inptr; \ + /* Switch to the character set designated last for SO. A faulty \ + input file may contain an SO byte without a prior SO \ + designation; treat such a lone SO as an illegal sequence. */ \ if ((ann & SO_ann) != 0) \ switch (ann & SO_ann) \ { \ @@ -276,6 +273,7 @@ enum { \ STANDARD_FROM_LOOP_ERR_HANDLER (1); \ } \ + ++inptr; \ continue; \ } \ else if (ch == SI) \ diff --git a/iconvdata/tst-iconv-iso-2022-cn-ext.c b/iconvdata/tst-iconv-iso-2022-cn-ext.c index 5559fceef1..39c34009e8 100644 --- a/iconvdata/tst-iconv-iso-2022-cn-ext.c +++ b/iconvdata/tst-iconv-iso-2022-cn-ext.c @@ -25,6 +25,7 @@ #include <support/xunistd.h> #include <support/check.h> +#include <support/next_to_fault.h> #include <support/support.h> /* The test sets up a two memory page buffer with the second page marked @@ -37,6 +38,177 @@ character sets and may run out of buffer space while doing the operation. */ +/* FROM-direction regression tests for bug 34774: a lone SO (0x0e) + without any announced SO designation. The error paths must leave + the input pointer on the offending SO byte, and //IGNORE must skip + it exactly once. */ + +static void +test_lone_so_plain (void) +{ + iconv_t cd = iconv_open ("UTF-8", "ISO-2022-CN-EXT"); + TEST_VERIFY_EXIT (cd != (iconv_t) -1); + char in[] = { 0x0e }; + char out[8]; + char *ip = in, *op = out; + size_t il = sizeof in, ol = sizeof out; + errno = 0; + TEST_COMPARE (iconv (cd, &ip, &il, &op, &ol), (size_t) -1); + TEST_COMPARE (errno, EILSEQ); + TEST_VERIFY (ip == in); + TEST_COMPARE (il, (size_t) 1); + TEST_COMPARE (iconv_close (cd), 0); +} + +static void +test_so_after_ascii (void) +{ + iconv_t cd = iconv_open ("UTF-8", "ISO-2022-CN-EXT"); + TEST_VERIFY_EXIT (cd != (iconv_t) -1); + char in[] = { 'A', 0x0e, 'B' }; + char out[8]; + char *ip = in, *op = out; + size_t il = sizeof in, ol = sizeof out; + errno = 0; + TEST_COMPARE (iconv (cd, &ip, &il, &op, &ol), (size_t) -1); + TEST_COMPARE (errno, EILSEQ); + TEST_VERIFY (ip == in + 1); + TEST_COMPARE (il, (size_t) 2); + TEST_VERIFY (op == out + 1); + TEST_COMPARE_BLOB (out, op - out, "A", 1); + TEST_COMPARE (iconv_close (cd), 0); +} + +static void +test_lone_so_ignore (void) +{ + iconv_t cd = iconv_open ("UTF-8//IGNORE", "ISO-2022-CN-EXT"); + TEST_VERIFY_EXIT (cd != (iconv_t) -1); + char in[] = { 0x0e, 'A', 'B' }; + char out[8]; + char *ip = in, *op = out; + size_t il = sizeof in, ol = sizeof out; + errno = 0; + /* With //IGNORE the offending SO must be skipped exactly once and the + following ASCII must be converted. Note that glibc still reports + EILSEQ here: the ignore arm of STANDARD_FROM_LOOP_ERR_HANDLER does + not reset result, which stays __GCONV_ILLEGAL_INPUT, and the + iconv() wrapper maps that status to -1 plus EILSEQ + unconditionally (iconv/iconv.c). */ + TEST_COMPARE (iconv (cd, &ip, &il, &op, &ol), (size_t) -1); + TEST_COMPARE (errno, EILSEQ); + TEST_VERIFY (ip == in + 3); + TEST_COMPARE (il, (size_t) 0); + TEST_COMPARE_BLOB (out, op - out, "AB", 2); + TEST_COMPARE (iconv_close (cd), 0); +} + +static void +test_caller_skip_no_underflow (void) +{ + /* A caller that skips the offending byte on EILSEQ and calls + iconv() again. With the fix, the first call reports the SO as + unconsumed input, so the skip drops the SO itself and the rest of + the input still converts. */ + iconv_t cd = iconv_open ("UTF-8", "ISO-2022-CN-EXT"); + TEST_VERIFY_EXIT (cd != (iconv_t) -1); + char in[] = { 0x0e, 'A' }; + char out[8]; + char *ip = in, *op = out; + size_t il = sizeof in, ol = sizeof out; + errno = 0; + TEST_COMPARE (iconv (cd, &ip, &il, &op, &ol), (size_t) -1); + TEST_COMPARE (errno, EILSEQ); + /* The SO is the offending byte and must still be unconsumed; do not + run the caller-side skip unless this precondition holds, or the + test itself would advance past the end of the input. */ + TEST_VERIFY_EXIT (ip == in); + TEST_VERIFY_EXIT (il == 2); + ++ip; + --il; + op = out; + ol = sizeof out; + errno = 0; + TEST_COMPARE (iconv (cd, &ip, &il, &op, &ol), (size_t) 0); + TEST_COMPARE (il, (size_t) 0); + TEST_COMPARE ((size_t) (op - out), (size_t) 1); + TEST_COMPARE_BLOB (out, op - out, "A", 1); + TEST_COMPARE (iconv_close (cd), 0); +} + +static void +test_lone_so_tail_caller_skip (void) +{ + /* A lone SO at the end of the input. Before the fix the first call + consumed the SO and left the remaining length at 0, so a caller + skipping the offending byte decremented that length to + (size_t) -1. */ + iconv_t cd = iconv_open ("UTF-8", "ISO-2022-CN-EXT"); + TEST_VERIFY_EXIT (cd != (iconv_t) -1); + char in[] = { 'A', 0x0e }; + char out[8]; + char *ip = in, *op = out; + size_t il = sizeof in, ol = sizeof out; + errno = 0; + TEST_COMPARE (iconv (cd, &ip, &il, &op, &ol), (size_t) -1); + TEST_COMPARE (errno, EILSEQ); + TEST_VERIFY_EXIT (ip == in + 1); + TEST_VERIFY_EXIT (il == 1); + ++ip; + --il; + op = out; + ol = sizeof out; + errno = 0; + TEST_COMPARE (iconv (cd, &ip, &il, &op, &ol), (size_t) 0); + TEST_COMPARE (il, (size_t) 0); + TEST_COMPARE (iconv_close (cd), 0); +} + +static void +test_designated_so (void) +{ + /* Positive case: with an announced designation the SO switches to + the designated set, consumes exactly one byte, and the following + 7-bit GB2312 pair converts. ESC $ ) A designates GB2312; + 0x52 0x3b is the 7-bit form of the GB2312 code for U+4E00. */ + iconv_t cd = iconv_open ("UTF-8", "ISO-2022-CN-EXT"); + TEST_VERIFY_EXIT (cd != (iconv_t) -1); + char in[] = { 0x1b, '$', ')', 'A', 0x0e, 0x52, 0x3b, 0x0f, 'Z' }; + char out[16]; + char *ip = in, *op = out; + size_t il = sizeof in, ol = sizeof out; + errno = 0; + TEST_COMPARE (iconv (cd, &ip, &il, &op, &ol), (size_t) 0); + TEST_COMPARE (il, (size_t) 0); + TEST_COMPARE ((size_t) (op - out), (size_t) 4); + TEST_COMPARE_BLOB (out, 4, "\xe4\xb8\x80Z", 4); + TEST_COMPARE (iconv_close (cd), 0); +} + +static void +test_trailing_so_ignore (void) +{ + /* The shape from bug 34774: a lone SO as the last input byte with + //IGNORE. Place the input right before an inaccessible page so + that a read past the end faults. */ + struct support_next_to_fault ntf = support_next_to_fault_allocate (2); + ntf.buffer[0] = 'A'; + ntf.buffer[1] = 0x0e; + iconv_t cd = iconv_open ("UTF-8//IGNORE", "ISO-2022-CN-EXT"); + TEST_VERIFY_EXIT (cd != (iconv_t) -1); + char out[8]; + char *ip = ntf.buffer, *op = out; + size_t il = 2, ol = sizeof out; + errno = 0; + TEST_COMPARE (iconv (cd, &ip, &il, &op, &ol), (size_t) -1); + TEST_COMPARE (errno, EILSEQ); + TEST_VERIFY (ip == ntf.buffer + 2); + TEST_COMPARE (il, (size_t) 0); + TEST_COMPARE_BLOB (out, op - out, "A", 1); + TEST_COMPARE (iconv_close (cd), 0); + support_next_to_fault_free (&ntf); +} + static int do_test (void) { @@ -122,6 +294,14 @@ do_test (void) xmunmap (ntf, ntfsize); + test_trailing_so_ignore (); + test_lone_so_plain (); + test_so_after_ascii (); + test_lone_so_ignore (); + test_caller_skip_no_underflow (); + test_lone_so_tail_caller_skip (); + test_designated_so (); + return 0; } -- 2.56.1 ++++++ regex-alloc-fail-double-free.patch ++++++ >From fcfb867c58ab5dc402a072fe23534fa3b8ff2616 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella <[email protected]> Date: Wed, 11 Nov 2026 10:57:38 -0300 Subject: [PATCH] posix: Fix double free after allocation failure in regcomp and regexec (BZ 34991, CVE-2026-100290) The re_dfa_add_node and build_range_exp grow paired arrays with consecutive reallocs and store the results only after all of them succeed. If a later realloc fails, the structure keeps pointers to freed blocks, and the cleanup frees them again (BZ 31935). Store each result as soon as its realloc succeeds, as gnulib commit 9db7e04d15 did for re_dfa_add_node. Also, the match_ctx_add_entry frees bkref_ents when growing it fails but keeps thepointer, so match_ctx_free frees it again. Keep the old array instead. The tst-regcomp-bracket-free now also covers the re_dfa_add_node and build_range_exp paths. Checked on x86_64-linux-gnu and i686-linux-gnu. (cherry picked from commit 2a605083deb2c26e93b3be9943f5139e932c9f96) --- posix/Makefile | 1 + posix/regcomp.c | 18 +-- posix/regex_internal.c | 22 ++- posix/regexec.c | 5 +- posix/tst-regcomp-bracket-free.c | 223 ++++++++++++++++++++++++++----- 5 files changed, 212 insertions(+), 57 deletions(-) diff --git a/posix/Makefile b/posix/Makefile index 7478cc2174..e3a24c6a85 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -566,6 +566,7 @@ $(objpfx)tst-regexloc.out: $(gen-locales) $(objpfx)tst-rxspencer.out: $(gen-locales) $(objpfx)tst-rxspencer-no-utf8.out: $(gen-locales) $(objpfx)tst-regcomp-truncated.out: $(gen-locales) +$(objpfx)tst-regcomp-bracket-free.out: $(gen-locales) endif # If we will use the generic uname implementation, we must figure out what diff --git a/posix/regcomp.c b/posix/regcomp.c index 22b4d32de5..ff0b8f3dfa 100644 --- a/posix/regcomp.c +++ b/posix/regcomp.c @@ -2758,19 +2758,17 @@ build_range_exp (const reg_syntax_t syntax, are NULL if *range_alloc == 0. */ new_array_start = re_realloc (mbcset->range_starts, wchar_t, new_nranges); + if (new_array_start != NULL) + mbcset->range_starts = new_array_start; new_array_end = re_realloc (mbcset->range_ends, wchar_t, new_nranges); + if (new_array_end != NULL) + mbcset->range_ends = new_array_end; if (__glibc_unlikely (new_array_start == NULL || new_array_end == NULL)) - { - re_free (new_array_start); - re_free (new_array_end); - return REG_ESPACE; - } + return REG_ESPACE; - mbcset->range_starts = new_array_start; - mbcset->range_ends = new_array_end; *range_alloc = new_nranges; } @@ -2990,15 +2988,17 @@ build_range_exp (bitset_t sbcset, re_charset_t *mbcset, Idx *range_alloc, new_nranges = 2 * mbcset->nranges + 1; new_array_start = re_realloc (mbcset->range_starts, uint32_t, new_nranges); + if (new_array_start != NULL) + mbcset->range_starts = new_array_start; new_array_end = re_realloc (mbcset->range_ends, uint32_t, new_nranges); + if (new_array_end != NULL) + mbcset->range_ends = new_array_end; if (__glibc_unlikely (new_array_start == NULL || new_array_end == NULL)) return REG_ESPACE; - mbcset->range_starts = new_array_start; - mbcset->range_ends = new_array_end; *range_alloc = new_nranges; } diff --git a/posix/regex_internal.c b/posix/regex_internal.c index 5e0925dff9..b820136c86 100644 --- a/posix/regex_internal.c +++ b/posix/regex_internal.c @@ -1430,24 +1430,22 @@ re_dfa_add_node (re_dfa_t *dfa, re_token_t token) if (__glibc_unlikely (new_nodes == NULL)) return -1; dfa->nodes = new_nodes; + dfa->nodes_alloc = new_nodes_alloc; new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc); + if (new_nexts != NULL) + dfa->nexts = new_nexts; new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc); + if (new_indices != NULL) + dfa->org_indices = new_indices; new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc); + if (new_edests != NULL) + dfa->edests = new_edests; new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc); + if (new_eclosures != NULL) + dfa->eclosures = new_eclosures; if (__glibc_unlikely (new_nexts == NULL || new_indices == NULL || new_edests == NULL || new_eclosures == NULL)) - { - re_free (new_nexts); - re_free (new_indices); - re_free (new_edests); - re_free (new_eclosures); - return -1; - } - dfa->nexts = new_nexts; - dfa->org_indices = new_indices; - dfa->edests = new_edests; - dfa->eclosures = new_eclosures; - dfa->nodes_alloc = new_nodes_alloc; + return -1; } dfa->nodes[dfa->nodes_len] = token; dfa->nodes[dfa->nodes_len].constraint = 0; diff --git a/posix/regexec.c b/posix/regexec.c index 9ac5565295..cf1d405018 100644 --- a/posix/regexec.c +++ b/posix/regexec.c @@ -4148,10 +4148,7 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry, mctx->abkref_ents * 2); if (__glibc_unlikely (new_entry == NULL)) - { - re_free (mctx->bkref_ents); - return REG_ESPACE; - } + return REG_ESPACE; mctx->bkref_ents = new_entry; memset (mctx->bkref_ents + mctx->nbkref_ents, '\0', sizeof (struct re_backref_cache_entry) * mctx->abkref_ents); diff --git a/posix/tst-regcomp-bracket-free.c b/posix/tst-regcomp-bracket-free.c index 209b8802c6..f69c2292e6 100644 --- a/posix/tst-regcomp-bracket-free.c +++ b/posix/tst-regcomp-bracket-free.c @@ -1,4 +1,4 @@ -/* Test regcomp bracket parsing with injected allocation failures (bug 33185). +/* Test regcomp parsing with injected allocation failures (bug 33185). Copyright (C) 2025-2026 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -19,15 +19,25 @@ /* This test invokes regcomp multiple times, failing one memory allocation in each call. The function call should fail with REG_ESPACE (or succeed if it can recover from the allocation - failure). Previously, there was double-free bug. */ + failure). Previously, there were double-free bugs on the partial + allocation-failure paths of parse_bracket_exp (bug 33185), + re_dfa_add_node and build_range_exp (bugs 31935 and 34991). + + To detect these deterministically, the allocator is interposed and + every pointer it hands out is tracked while a regcomp call is in + progress. */ #include <errno.h> +#include <locale.h> #include <regex.h> +#include <stdbool.h> +#include <stddef.h> #include <stdio.h> #include <string.h> #include <support/check.h> #include <support/namespace.h> #include <support/support.h> +#include <support/xdlfcn.h> /* Data structure allocated via MAP_SHARED, so that writes from the subprocess are visible. */ @@ -39,8 +49,12 @@ struct shared_data /* If this number is reached, one allocation fails. */ volatile unsigned int failing_allocation; - /* The subprocess stores the expected name here. */ - char name[100]; + /* Incremented by the free interposer when a double free or a free of + a stale pointer is detected during a tracked call. */ + volatile unsigned int corruption; + + /* Set nonzero if the tracking registry overflows. */ + volatile unsigned int overflow; }; /* Allocation count in shared mapping. */ @@ -60,7 +74,81 @@ fail_this_allocation (void) return false; } -/* Failure-injecting wrappers for allocation functions used by glibc. */ +/* While TRACKING is set, every pointer returned by the allocator is recorded, + and free is validated against the recorded set. The registry itself never + allocates. */ +enum { HEAP_MAX = 8192 }; +static void *heap_ptr[HEAP_MAX]; +static bool heap_live[HEAP_MAX]; +static size_t heap_count; +static bool tracking; + +static void *(*real_malloc) (size_t); +static void *(*real_calloc) (size_t, size_t); +static void *(*real_realloc) (void *, size_t); +static void (*real_free) (void *); + +static void __attribute__ ((constructor)) +resolve_allocator (void) +{ + real_malloc = xdlsym (RTLD_NEXT, "malloc"); + real_calloc = xdlsym (RTLD_NEXT, "calloc"); + real_realloc = xdlsym (RTLD_NEXT, "realloc"); + real_free = xdlsym (RTLD_NEXT, "free"); +} + +static void +heap_track_reset (void) +{ + heap_count = 0; +} + +static void +heap_record_alloc (void *p) +{ + if (p == NULL) + return; + for (size_t i = 0; i < heap_count; ++i) + if (heap_ptr[i] == p) + { + heap_live[i] = true; + return; + } + if (heap_count < HEAP_MAX) + { + heap_ptr[heap_count] = p; + heap_live[heap_count] = true; + ++heap_count; + } + else if (shared != NULL) + shared->overflow = shared->overflow + 1; +} + +/* Result of validating a free against the tracking registry. */ +enum heap_free_status +{ + HEAP_FREE_OK, /* P was live and is now marked released. */ + HEAP_FREE_DOUBLE, /* P was already released (double or stale free). */ + HEAP_FREE_UNTRACKED, /* P is not tracked (allocated before tracking). */ +}; + +/* Mark P as released and report whether the free is valid. */ +static enum heap_free_status +heap_record_free (void *p) +{ + for (size_t i = 0; i < heap_count; ++i) + if (heap_ptr[i] == p) + { + if (!heap_live[i]) + return HEAP_FREE_DOUBLE; + heap_live[i] = false; + return HEAP_FREE_OK; + } + return HEAP_FREE_UNTRACKED; +} + +/* Failure-injecting, tracking wrappers for the allocation functions + used by glibc. */ void * malloc (size_t size) @@ -70,8 +158,10 @@ malloc (size_t size) errno = ENOMEM; return NULL; } - extern __typeof (malloc) __libc_malloc; - return __libc_malloc (size); + void *p = real_malloc (size); + if (tracking) + heap_record_alloc (p); + return p; } void * @@ -82,8 +172,10 @@ calloc (size_t a, size_t b) errno = ENOMEM; return NULL; } - extern __typeof (calloc) __libc_calloc; - return __libc_calloc (a, b); + void *p = real_calloc (a, b); + if (tracking) + heap_record_alloc (p); + return p; } void * @@ -94,8 +186,33 @@ realloc (void *ptr, size_t size) errno = ENOMEM; return NULL; } - extern __typeof (realloc) __libc_realloc; - return __libc_realloc (ptr, size); + void *p = real_realloc (ptr, size); + if (tracking && p != NULL) + { + if (ptr != NULL && p != ptr) + heap_record_free (ptr); + heap_record_alloc (p); + } + return p; +} + +void +free (void *ptr) +{ + if (ptr == NULL) + return; + if (tracking) + { + if (heap_record_free (ptr) == HEAP_FREE_DOUBLE) + { + /* Record it and drop the free so the heap is not corrupted + further. */ + if (shared != NULL) + shared->corruption = shared->corruption + 1; + return; + } + } + real_free (ptr); } /* No-op subprocess to verify that support_isolate_in_subprocess does @@ -105,6 +222,27 @@ no_op (void *ignored) { } +/* regcomp flags for the pattern under test. */ +static int test_cflags; + +static int +compile_tracked (const char *regexp) +{ + regex_t reg; + heap_track_reset (); + shared->corruption = 0; + shared->overflow = 0; + tracking = true; + int ret = regcomp (®, regexp, test_cflags); + tracking = false; + if (ret == 0) + regfree (®); + TEST_COMPARE (shared->corruption, 0); + /* A registry overflow means tracking was incomplete. */ + TEST_COMPARE (shared->overflow, 0); + return ret; +} + /* Perform a regcomp call in a subprocess. Used to count its allocations. */ static void @@ -114,8 +252,7 @@ initialize (void *regexp1) shared->allocation_count = 0; - regex_t reg; - TEST_COMPARE (regcomp (®, regexp, 0), 0); + TEST_COMPARE (compile_tracked (regexp), 0); } /* Perform regcomp in a subprocess with fault injection. */ @@ -125,8 +262,7 @@ test_in_subprocess (void *regexp1) const char *regexp = regexp1; unsigned int inject_at = shared->failing_allocation; - regex_t reg; - int ret = regcomp (®, regexp, 0); + int ret = compile_tracked (regexp); if (ret != 0) { @@ -137,11 +273,39 @@ test_in_subprocess (void *regexp1) } } +static void +run_pattern (const char *regexp, int cflags, const char *locale) +{ + test_cflags = cflags; + + /* Disable fault injection before switching locale, setlocale must not + see an injected failure. */ + shared->failing_allocation = ~0U; + xsetlocale (LC_ALL, locale == NULL ? "C" : locale); + + /* Count the allocations of a successful call. */ + support_isolate_in_subprocess (initialize, (void *) regexp); + + /* The number of allocations in the successful case, plus some + slack. Once the number of expected allocations is exceeded, + injecting further failures does not make a difference. */ + unsigned int maximum_allocation_count = shared->allocation_count; + printf ("info: pattern \"%s\" (locale %s) performs %u allocations\n", + regexp, locale == NULL ? "C" : locale, maximum_allocation_count); + maximum_allocation_count += 10; + + for (unsigned int inject_at = 0; inject_at <= maximum_allocation_count; + ++inject_at) + { + shared->allocation_count = 0; + shared->failing_allocation = inject_at; + support_isolate_in_subprocess (test_in_subprocess, (void *) regexp); + } +} + static int do_test (void) { - char regexp[] = "[:alpha:]"; - shared = support_shared_allocate (sizeof (*shared)); /* Disable fault injection. */ @@ -150,23 +314,18 @@ do_test (void) support_isolate_in_subprocess (no_op, NULL); TEST_COMPARE (shared->allocation_count, 0); - support_isolate_in_subprocess (initialize, regexp); + /* Bracket expression parsing (parse_bracket_exp, bug 33185). */ + run_pattern ("[:alpha:]", 0, NULL); - /* The number of allocations in the successful case, plus some - slack. Once the number of expected allocations is exceeded, - injecting further failures does not make a difference. */ - unsigned int maximum_allocation_count = shared->allocation_count; - printf ("info: successful call performs %u allocations\n", - maximum_allocation_count); - maximum_allocation_count += 10; + /* NFA node array growth in re_dfa_add_node (bug 34991). The initial + nodes_alloc is the pattern length + 1; the interval duplicates the + 'a' node 64 times, so the node arrays are grown several times. */ + run_pattern ("a{64}", REG_EXTENDED, NULL); - for (unsigned int inject_at = 0; inject_at <= maximum_allocation_count; - ++inject_at) - { - shared->allocation_count = 0; - shared->failing_allocation = inject_at; - support_isolate_in_subprocess (test_in_subprocess, regexp); - } + /* Range array growth in build_range_exp (bugs 31935 and 34991). A + multibyte locale stores the ranges in the mbcset arrays, and + multiple ranges force the growth realloc. */ + run_pattern ("[a-bc-de-fg-hi-jk-lm-no-pq-rs-t]", 0, "en_US.UTF-8"); support_shared_free (shared); -- 2.56.1 ++++++ wide-scanf-double-null.patch ++++++ >From 063fdd4c7e034dfc1a0f14dbf3a9718a502033cf Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella <[email protected]> Date: Fri, 9 Oct 2026 13:18:07 -0300 Subject: [PATCH] stdio-common: Fix double null terminator in wide scanf %s and %[ (BZ 34989, CVE-2026-115819) For %s and %[ without the 'l' modifier, the wide scanf functions convert the input into the char array with __wcrtomb. To emit the sequence that returns to the initial shift state, the conversion is finished with __wcrtomb (buf, L'\0', &state), which also stores the terminating null byte, and the N bytes are copied to the output. The code then appends another null byte, so two are written. If the input fills the field width, an array sized for the converted string plus its terminator (as C requires) is written one byte past its end, for instance: char buf[5]; swscanf (L"abcd", L"%4s", buf); stores "abcd\0\0". The 'm' modifier allocated one extra byte for it, which was later trimmed. Only append the null byte explicitly for the narrow scanf, and size the 'm' buffer for the N bytes from __wcrtomb. The new test checks swscanf and fwscanf with the destination placed right before a PROT_NONE page, in the C and a UTF-8 locale, and the 'm' modifier allocation for a range of string lengths. Checked on x86_64-linux-gnu. Reported-by: Russell Miller <[email protected]> (cherry picked from commit 3ccbe46830772e17c460a1d28a884a7c59b03d35) --- stdio-common/Makefile | 2 + stdio-common/tst-wscanf-nul.c | 169 ++++++++++++++++++++++++++++++++ stdio-common/vfscanf-internal.c | 30 +++--- 3 files changed, 189 insertions(+), 12 deletions(-) create mode 100644 stdio-common/tst-wscanf-nul.c diff --git a/stdio-common/Makefile b/stdio-common/Makefile index a948bfde8f..034bc8de3a 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -353,6 +353,7 @@ tests := \ tst-vfscanf-bz34008 \ tst-wc-printf \ tst-wscanf-bz34208 \ + tst-wscanf-nul \ tstdiomisc \ tstgetln \ tstscanf \ @@ -560,6 +561,7 @@ $(objpfx)tst-vfprintf-mbs-prec.out: $(gen-locales) $(objpfx)tst-vfprintf-width-i18n.out: $(gen-locales) $(objpfx)tst-grouping3.out: $(gen-locales) $(objpfx)tst-scanf-to_inpunct.out: $(gen-locales) +$(objpfx)tst-wscanf-nul.out: $(gen-locales) endif tst-printf-bz18872-ENV = MALLOC_TRACE=$(objpfx)tst-printf-bz18872.mtrace \ diff --git a/stdio-common/tst-wscanf-nul.c b/stdio-common/tst-wscanf-nul.c new file mode 100644 index 0000000000..bda1bcd7ed --- /dev/null +++ b/stdio-common/tst-wscanf-nul.c @@ -0,0 +1,169 @@ +/* Test that wide scanf %s and %[ store a single null terminator. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <array_length.h> +#include <limits.h> +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <wchar.h> +#include <support/check.h> +#include <support/next_to_fault.h> +#include <support/support.h> +#include <support/test-driver.h> +#include <support/xstdio.h> + +struct test +{ + const wchar_t *input; + const wchar_t *format; + /* The same conversion with the 'm' modifier. */ + const wchar_t *mformat; + /* Multibyte result, without the terminating null byte. */ + const char *expected; +}; + +static const struct test tests_c[] = + { + { L"abcd", L"%4s", L"%4ms", "abcd" }, + { L"abcdef", L"%4s", L"%4ms", "abcd" }, + { L"ab", L"%4s", L"%4ms", "ab" }, + { L"abcd", L"%s", L"%ms", "abcd" }, + { L"a", L"%1s", L"%1ms", "a" }, + { L"abcd", L"%4[a-z]", L"%4m[a-z]", "abcd" }, + { L"abcdef", L"%4[a-z]", L"%4m[a-z]", "abcd" }, + { L"abcd", L"%[^x]", L"%m[^x]", "abcd" }, + }; + +static const struct test tests_utf8[] = + { + { L"\u00e4\u00f6\u00fc", L"%3s", L"%3ms", "\xc3\xa4\xc3\xb6\xc3\xbc" }, + { L"\u00e4\u00f6\u00fcx", L"%3s", L"%3ms", "\xc3\xa4\xc3\xb6\xc3\xbc" }, + { L"\u00e4\u00f6\u00fc", L"%s", L"%ms", "\xc3\xa4\xc3\xb6\xc3\xbc" }, + { L"\u00e4\u00f6\u00fc", L"%3[^x]", L"%3m[^x]", + "\xc3\xa4\xc3\xb6\xc3\xbc" }, + { L"\u00e4\u00f6\u00fcx", L"%[^x]", L"%m[^x]", + "\xc3\xa4\xc3\xb6\xc3\xbc" }, + }; + +/* Store the conversion into a buffer of exactly the size required for + the expected result and its terminator, followed by an inaccessible + page, so a write past the terminator faults. */ +static void +check_buffer (const struct test *t, FILE *fp) +{ + size_t size = strlen (t->expected) + 1; + struct support_next_to_fault ntf = support_next_to_fault_allocate (size); + memset (ntf.buffer, 0xff, size); + + int r = fp == NULL + ? swscanf (t->input, t->format, ntf.buffer) + : fwscanf (fp, t->format, ntf.buffer); + TEST_COMPARE (r, 1); + TEST_COMPARE_BLOB (ntf.buffer, size, t->expected, size); + + support_next_to_fault_free (&ntf); +} + +/* Same as check_buffer, but with the 'm' modifier allocating the + result. */ +static void +check_malloc (const struct test *t, FILE *fp) +{ + char *p = NULL; + int r = fp == NULL + ? swscanf (t->input, t->mformat, &p) + : fwscanf (fp, t->mformat, &p); + TEST_COMPARE (r, 1); + TEST_COMPARE_STRING (p, t->expected); + free (p); +} + +static void +check_test (const struct test *t) +{ + if (test_verbose > 0) + printf ("info: input \"%ls\" format \"%ls\"\n", t->input, t->format); + + check_buffer (t, NULL); + check_malloc (t, NULL); + + /* fmemopen streams can not be wide oriented, so use a temporary + file instead. */ + FILE *fp = tmpfile (); + TEST_VERIFY_EXIT (fp != NULL); + TEST_VERIFY_EXIT (fputws (t->input, fp) >= 0); + rewind (fp); + check_buffer (t, fp); + rewind (fp); + check_malloc (t, fp); + xfclose (fp); +} + +/* Exercise the 'm' modifier buffer growth for a range of input + lengths, where each input character converts to CHARLEN bytes. */ +static void +check_alloc (wchar_t wc, const char *mb, size_t charlen) +{ + enum { maxlen = 300 }; + wchar_t input[maxlen + 1]; + char expected[maxlen * MB_LEN_MAX + 1]; + + for (size_t len = 1; len <= maxlen; len++) + { + for (size_t i = 0; i < len; i++) + { + input[i] = wc; + memcpy (expected + i * charlen, mb, charlen); + } + input[len] = L'\0'; + expected[len * charlen] = '\0'; + + char *p = NULL; + TEST_COMPARE (swscanf (input, L"%ms", &p), 1); + TEST_COMPARE_STRING (p, expected); + free (p); + + p = NULL; + TEST_COMPARE (swscanf (input, L"%m[^x]", &p), 1); + TEST_COMPARE_STRING (p, expected); + free (p); + } +} + +static int +do_test (void) +{ + for (size_t i = 0; i < array_length (tests_c); i++) + check_test (&tests_c[i]); + check_alloc (L'a', "a", 1); + + xsetlocale (LC_ALL, "de_DE.UTF-8"); + for (size_t i = 0; i < array_length (tests_c); i++) + check_test (&tests_c[i]); + for (size_t i = 0; i < array_length (tests_utf8); i++) + check_test (&tests_utf8[i]); + check_alloc (L'a', "a", 1); + check_alloc (L'\u00e4', "\xc3\xa4", 2); + check_alloc (L'\u20ac', "\xe2\x82\xac", 3); + + return 0; +} + +#include <support/test-driver.c> diff --git a/stdio-common/vfscanf-internal.c b/stdio-common/vfscanf-internal.c index 5f548f709f..201d679809 100644 --- a/stdio-common/vfscanf-internal.c +++ b/stdio-common/vfscanf-internal.c @@ -1217,17 +1217,19 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr, { #ifdef COMPILE_WSCANF /* We have to emit the code to get into the initial - state. */ + state. __wcrtomb also stores the terminating null + byte, which is included in N. */ char buf[MB_LEN_MAX]; size_t n = __wcrtomb (buf, L'\0', &state); - if (n > 0 && (flags & MALLOC) - && str + n >= *strptr + strsize) + if (__glibc_unlikely (n == (size_t) -1)) + encode_error (); + if ((flags & MALLOC) && str - *strptr + n > strsize) { /* Enlarge the buffer. */ size_t strleng = str - *strptr; char *newstr; - newstr = (char *) realloc (*strptr, strleng + n + 1); + newstr = (char *) realloc (*strptr, strleng + n); if (newstr == NULL) { if (flags & POSIX_MALLOC) @@ -1247,13 +1249,14 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr, { *strptr = newstr; str = newstr + strleng; - strsize = strleng + n + 1; + strsize = strleng + n; } } str = __mempcpy (str, buf, n); -#endif +#else *str++ = '\0'; +#endif if ((flags & MALLOC) && str - *strptr != strsize) { @@ -3145,17 +3148,19 @@ digits_extended_fail: { #ifdef COMPILE_WSCANF /* We have to emit the code to get into the initial - state. */ + state. __wcrtomb also stores the terminating null + byte, which is included in N. */ char buf[MB_LEN_MAX]; size_t n = __wcrtomb (buf, L'\0', &state); - if (n > 0 && (flags & MALLOC) - && str + n >= *strptr + strsize) + if (__glibc_unlikely (n == (size_t) -1)) + encode_error (); + if ((flags & MALLOC) && str - *strptr + n > strsize) { /* Enlarge the buffer. */ size_t strleng = str - *strptr; char *newstr; - newstr = (char *) realloc (*strptr, strleng + n + 1); + newstr = (char *) realloc (*strptr, strleng + n); if (newstr == NULL) { if (flags & POSIX_MALLOC) @@ -3175,13 +3180,14 @@ digits_extended_fail: { *strptr = newstr; str = newstr + strleng; - strsize = strleng + n + 1; + strsize = strleng + n; } } str = __mempcpy (str, buf, n); -#endif +#else *str++ = '\0'; +#endif if ((flags & MALLOC) && str - *strptr != strsize) { -- 2.56.1
