[packages/glibc] Rel 6. Move gnu/lib-names-*.h to -devel, drop dead -isa- P/O

arekm arekm at pld-linux.org
Sun Nov 15 21:26:40 CET 2026


commit 5375b81383473de2a32d58bdbddba81bce10641c
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Sun Nov 15 15:06:55 2026 +0100

    Rel 6. Move gnu/lib-names-*.h to -devel, drop dead -isa- P/O
    
    gnu/lib-names-{32,64,x32}.h are per-ABI, but sat in glibc-headers, of
    which only one arch is installed on multilib hosts, so gcc -m32 (and
    -m64 on x32) failed on the missing lib-names-<abi>.h. They now go
    to glibc-devel of each arch; glibc-headers is identical on x86_64, i686
    and x32.
    
    The glibc-headers-isa-* and glibc-devel-utils-isa-* Provides/Obsoletes
    never worked: rpm.org matches Obsoletes against package names only
    (since 4.4.2.1), not Provides. Drop them.
    glibc-devel.i686 provides glibc-devel(ix86) again, which
    gcc-multilib-32, llvm and linux-kvm require.
    
    Fixes for CVE-2026-115819, CVE-2026-100290, CVE-2026-84243.

 glibc-CVE-2026-100290.patch | 427 ++++++++++++++++++++++++++++++++++++++++++++
 glibc-CVE-2026-115819.patch | 277 ++++++++++++++++++++++++++++
 glibc.spec                  |  63 ++-----
 3 files changed, 720 insertions(+), 47 deletions(-)
---
diff --git a/glibc.spec b/glibc.spec
index c177b33..9be6ac1 100644
--- a/glibc.spec
+++ b/glibc.spec
@@ -57,7 +57,7 @@ Summary(tr.UTF-8):	GNU libc
 Summary(uk.UTF-8):	GNU libc версії
 Name:		glibc
 Version:	%{core_version}
-Release:	5
+Release:	6
 Epoch:		6
 License:	LGPL v2.1+
 Group:		Libraries
@@ -74,7 +74,7 @@ Source7:	%{name}-LD-path.c
 Source9:	nscd.tmpfiles
 # use branch.sh to update glibc-git.patch
 Patch0:		%{name}-git.patch
-# Patch0-md5:	f591cabb3221c15a92e613ed42c07832
+# Patch0-md5:	e931005f3a8758933f3ec440c1cb502f
 # against GNU TP (libc domain)
 #Patch1: %{name}-pl.po-update.patch
 Patch2:		%{name}-pld.patch
@@ -98,7 +98,10 @@ Patch23:	%{name}-pt_pax.patch
 
 Patch30:	%{name}-rh1124987.patch
 Patch31:	arm-widevine-compat.patch
-URL:		http://www.gnu.org/software/libc/
+# from master, not yet on release/2.44/master; drop once branch.sh brings them in
+Patch32:	%{name}-CVE-2026-115819.patch
+Patch33:	%{name}-CVE-2026-100290.patch
+URL:		https://www.gnu.org/software/libc/
 %{?with_selinux:BuildRequires:	audit-libs-devel}
 BuildRequires:	autoconf >= 2.71
 BuildRequires:	automake
@@ -442,6 +445,10 @@ Requires:	%{name}-devel-utils = %{epoch}:%{version}-%{release}
 Requires:	%{name}-headers = %{epoch}:%{version}-%{release}
 Requires:	libxcrypt-devel%{?_isa} >= 4.0.0
 Provides:	%{name}-devel(%{_target_cpu}) = %{epoch}:%{version}-%{release}
+%ifarch %{ix86}
+# required by gcc-multilib-32, llvm and linux-kvm
+Provides:	%{name}-devel(ix86) = %{epoch}:%{version}-%{release}
+%endif
 Obsoletes:	libiconv-devel
 %ifarch %{x8664}
 # see http://lists.pld-linux.org/mailman/pipermail/pld-devel-en/2016-May/024902.html
@@ -503,27 +510,6 @@ kitaplıklar.
 Summary:	Header files for development using standard C libraries
 Summary(pl.UTF-8):	Pliki nagłówkowe do tworzenia programów przy użyciu standardowych bibliotek C
 Group:		Development/Building
-# current rpm can't stand parentheses in Obsoletes
-%if "%{_isa}" != ""
-Provides:	glibc-headers-isa-%{__isa_name}-%{__isa_bits} = %{epoch}:%{version}-%{release}
-%endif
-%ifarch %{x8664} x32
-# If both -m32 and -m64 is to be supported on x86_64, x86_64 package
-# have to be installed, not ix86 one.
-Obsoletes:	glibc-headers-isa-x86-32 <= %{epoch}:%{version}-%{release}
-%endif
-%ifarch x32
-Obsoletes:	glibc-headers-isa-x86-64 <= %{epoch}:%{version}-%{release}
-%endif
-%ifarch ppc64
-Obsoletes:	glibc-headers-isa-ppc-32 <= %{epoch}:%{version}-%{release}
-%endif
-%ifarch s390x
-Obsoletes:	glibc-headers-isa-s390-32 <= %{epoch}:%{version}-%{release}
-%endif
-%ifarch sparc64
-Obsoletes:	glibc-headers-isa-sparc-32 <= %{epoch}:%{version}-%{release}
-%endif
 Requires:	linux-libc-headers >= %{llh_version}
 
 %description headers
@@ -551,27 +537,6 @@ korzystające ze standardowych bibliotek C.
 Summary:	Utilities needed for development using standard C libraries
 Summary(pl.UTF-8):	Narzędzia do tworzenia programów przy użyciu standardowych bibliotek C
 Group:		Development/Libraries
-# current rpm can't stand parentheses in Obsoletes
-%if "%{_isa}" != ""
-Provides:	glibc-devel-utils-isa-%{__isa_name}-%{__isa_bits} = %{epoch}:%{version}-%{release}
-%endif
-%ifarch %{x8664} x32
-# If both -m32 and -m64 is to be supported on AMD64, x86_64 package
-# have to be installed, not ix86 one.
-Obsoletes:	glibc-devel-utils-isa-x86-32 <= %{epoch}:%{version}-%{release}
-%endif
-%ifarch x32
-Obsoletes:	glibc-devel-utils-isa-x86-64 <= %{epoch}:%{version}-%{release}
-%endif
-%ifarch ppc64
-Obsoletes:	glibc-devel-utils-isa-ppc-32 <= %{epoch}:%{version}-%{release}
-%endif
-%ifarch s390x
-Obsoletes:	glibc-devel-utils-isa-s390-32 <= %{epoch}:%{version}-%{release}
-%endif
-%ifarch sparc64
-Obsoletes:	glibc-devel-utils-isa-sparc-32 <= %{epoch}:%{version}-%{release}
-%endif
 Conflicts:	man-pages < 4.00
 
 %description devel-utils
@@ -805,7 +770,7 @@ Provides:	localedb
 
 %description localedb-all
 This package contains locale database for all locales supported by
-glibc. In current glibc it's one large file (about 250MB - if you want
+glibc. In current glibc it's one large file (about 250MB) - if you want
 something smaller with support for chosen locales only, consider
 installing localedb-src and regenerating database using localedb-gen
 script (when database is generated, localedb-src can be uninstalled).
@@ -887,6 +852,8 @@ exit 1
 %ifarch %{arm} aarch64
 %patch -P31 -p1
 %endif
+%patch -P32 -p1
+%patch -P33 -p1
 
 # cleanup backups after patching
 find '(' -name '*~' -o -name '*.orig' ')' -print0 | xargs -0 -r -l512 rm -f
@@ -1790,6 +1757,7 @@ fi
 %ifarch %{ix86} %{x8664} x32 ppc ppc64 s390 s390x sparc sparcv9 sparc64 aarch64 armv6hl armv7hl armv7hnl
 # ABI-dependent headers
 %{_includedir}/gnu/stubs-*.h
+%{_includedir}/gnu/lib-names-*.h
 %endif
 
 %files headers
@@ -1803,7 +1771,8 @@ fi
 %dir %{_includedir}/finclude
 %{_includedir}/finclude/math-vector-fortran.h
 %dir %{_includedir}/gnu
-%{_includedir}/gnu/lib*.h
+%{_includedir}/gnu/lib-names.h
+%{_includedir}/gnu/libc-version.h
 %{_includedir}/gnu/stubs.h
 %{_includedir}/net
 %{_includedir}/netash
diff --git a/glibc-CVE-2026-100290.patch b/glibc-CVE-2026-100290.patch
new file mode 100644
index 0000000..be691b8
--- /dev/null
+++ b/glibc-CVE-2026-100290.patch
@@ -0,0 +1,427 @@
+Upstream 2a605083de "posix: Fix double free after allocation failure in regcomp and regexec (BZ 34991, CVE-2026-100290)"
+https://sourceware.org/git/?p=glibc.git;a=commit;h=2a605083de
+
+--- glibc-2.44.orig/posix/Makefile
++++ glibc-2.44/posix/Makefile
+@@ -566,6 +566,7 @@
+ $(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
+--- glibc-2.44.orig/posix/regcomp.c
++++ glibc-2.44/posix/regcomp.c
+@@ -2758,19 +2758,17 @@
+ 	       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 @@
+ 	  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;
+ 	}
+ 
+--- glibc-2.44.orig/posix/regex_internal.c
++++ glibc-2.44/posix/regex_internal.c
+@@ -1430,24 +1430,22 @@
+       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;
+--- glibc-2.44.orig/posix/regexec.c
++++ glibc-2.44/posix/regexec.c
+@@ -4148,10 +4148,7 @@
+       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);
+--- glibc-2.44.orig/posix/tst-regcomp-bracket-free.c
++++ glibc-2.44/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 @@
+   /* 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 @@
+     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 @@
+       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 @@
+       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 @@
+       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 @@
+ {
+ }
+ 
++/* 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 (&reg, regexp, test_cflags);
++  tracking = false;
++  if (ret == 0)
++    regfree (&reg);
++  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 @@
+ 
+   shared->allocation_count = 0;
+ 
+-  regex_t reg;
+-  TEST_COMPARE (regcomp (&reg, regexp, 0), 0);
++  TEST_COMPARE (compile_tracked (regexp), 0);
+ }
+ 
+ /* Perform regcomp in a subprocess with fault injection.  */
+@@ -125,8 +262,7 @@
+   const char *regexp = regexp1;
+   unsigned int inject_at = shared->failing_allocation;
+ 
+-  regex_t reg;
+-  int ret = regcomp (&reg, regexp, 0);
++  int ret = compile_tracked (regexp);
+ 
+   if (ret != 0)
+     {
+@@ -137,27 +273,25 @@
+     }
+ }
+ 
+-static int
+-do_test (void)
++static void
++run_pattern (const char *regexp, int cflags, const char *locale)
+ {
+-  char regexp[] = "[:alpha:]";
+-
+-  shared = support_shared_allocate (sizeof (*shared));
++  test_cflags = cflags;
+ 
+-  /* Disable fault injection.  */
++  /* Disable fault injection before switching locale, setlocale must not
++     see an injected failure.  */
+   shared->failing_allocation = ~0U;
++  xsetlocale (LC_ALL, locale == NULL ? "C" : locale);
+ 
+-  support_isolate_in_subprocess (no_op, NULL);
+-  TEST_COMPARE (shared->allocation_count, 0);
+-
+-  support_isolate_in_subprocess (initialize, regexp);
++  /* 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: successful call performs %u allocations\n",
+-          maximum_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;
+@@ -165,8 +299,33 @@
+     {
+       shared->allocation_count = 0;
+       shared->failing_allocation = inject_at;
+-      support_isolate_in_subprocess (test_in_subprocess, regexp);
++      support_isolate_in_subprocess (test_in_subprocess, (void *) regexp);
+     }
++}
++
++static int
++do_test (void)
++{
++  shared = support_shared_allocate (sizeof (*shared));
++
++  /* Disable fault injection.  */
++  shared->failing_allocation = ~0U;
++
++  support_isolate_in_subprocess (no_op, NULL);
++  TEST_COMPARE (shared->allocation_count, 0);
++
++  /* Bracket expression parsing (parse_bracket_exp, bug 33185).  */
++  run_pattern ("[:alpha:]", 0, NULL);
++
++  /* 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);
++
++  /* 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);
+ 
diff --git a/glibc-CVE-2026-115819.patch b/glibc-CVE-2026-115819.patch
new file mode 100644
index 0000000..24ebe6f
--- /dev/null
+++ b/glibc-CVE-2026-115819.patch
@@ -0,0 +1,277 @@
+Upstream 3ccbe46830 "stdio-common: Fix double null terminator in wide scanf %s and %[ (BZ 34989, CVE-2026-115819)"
+https://sourceware.org/git/?p=glibc.git;a=commit;h=3ccbe46830
+
+--- glibc-2.44.orig/stdio-common/Makefile
++++ glibc-2.44/stdio-common/Makefile
+@@ -353,6 +353,7 @@
+   tst-vfscanf-bz34008 \
+   tst-wc-printf \
+   tst-wscanf-bz34208 \
++  tst-wscanf-nul \
+   tstdiomisc \
+   tstgetln \
+   tstscanf \
+@@ -560,6 +561,7 @@
+ $(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 \
+--- glibc-2.44.orig/stdio-common/tst-wscanf-nul.c
++++ glibc-2.44/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>
+--- glibc-2.44.orig/stdio-common/vfscanf-internal.c
++++ glibc-2.44/stdio-common/vfscanf-internal.c
+@@ -1217,17 +1217,19 @@
+ 		{
+ #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 @@
+ 			{
+ 			  *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 @@
+ 		{
+ #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 @@
+ 			{
+ 			  *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)
+ 		    {
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/glibc.git/commitdiff/5375b81383473de2a32d58bdbddba81bce10641c



More information about the pld-cvs-commit mailing list