glibc/glibc-upstream-2.39-95.patch
Arjun Shankar 2a30b8f4b2 Sync with upstream branch release/2.39/master
Upstream commit: dcaf51b41e259387602774829c45222d0507f90a

- elf: Change ldconfig auxcache magic number (bug 32231)
- Make tst-strtod-underflow type-generic
- Add crt1-2.0.o for glibc 2.0 compatibility tests
- Add tests of more strtod special cases
- Add more tests of strtod end pointer
- Make tst-strtod2 and tst-strtod5 type-generic
- powerpc64le: Build new strtod tests with long double ABI flags (bug 32145)
- Do not set errno for overflowing NaN payload in strtod/nan (bug 32045)
- Improve NaN payload testing
- Make __strtod_internal tests type-generic
- Fix strtod subnormal rounding (bug 30220)
- More thoroughly test underflow / errno in tst-strtod-round
- Test errno setting on strtod overflow in tst-strtod-round
- Add tests of fread
- stdio-common: Add new test for fdopen
- libio: Attempt wide backup free only for non-legacy code
- debug: Fix read error handling in pcprofiledump
- elf: Fix tst-dlopen-tlsreinit1.out test dependency
- elf: Avoid re-initializing already allocated TLS in dlopen (bug 31717)
- elf: Clarify and invert second argument of _dl_allocate_tls_init
- elf: Support recursive use of dynamic TLS in interposed malloc
- nptl: Use <support/check.h> facilities in tst-setuid3
- posix: Use <support/check.h> facilities in tst-truncate and tst-truncate64
- ungetc: Fix backup buffer leak on program exit [BZ #27821]
- ungetc: Fix uninitialized read when putting into unused streams [BZ #27821]
- Make tst-ungetc use libsupport
- stdio-common: Add test for vfscanf with matches longer than INT_MAX [BZ #27650]
- support: Add FAIL test failure helper
- string: strerror, strsignal cannot use buffer after dlmopen (bug 32026)
- Define __libc_initial for the static libc
- x86: Fix bug in strchrnul-evex512 [BZ #32078]
- Adjust check-local-headers test for libaudit 4.0
- x32/cet: Support shadow stack during startup for Linux 6.10
- x86-64: Remove sysdeps/x86_64/x32/dl-machine.h
- support: Add options list terminator to the test driver
- manual/stdio: Further clarify putc, putwc, getc, and getwc
- Fix name space violation in fortify wrappers (bug 32052)
- resolv: Fix tst-resolv-short-response for older GCC (bug 32042)
- Add mremap tests
- mremap: Update manual entry
- linux: Update the mremap C implementation [BZ #31968]
- Enhanced test coverage for strncmp, wcsncmp
- Enhance test coverage for strnlen, wcsnlen

Resolves: RHEL-57776
Resolves: RHEL-57777
Resolves: RHEL-61392
2024-11-20 17:12:17 +01:00

197 lines
6.7 KiB
Diff

commit 3b25c7fa878c01f9e656701b5d59438ea2e49ba4
Author: Florian Weimer <fweimer@redhat.com>
Date: Wed Jun 26 11:27:54 2024 +0200
Enhance test coverage for strnlen, wcsnlen
This commit adds string/test-strnlen-nonarray and
wcsmbs/test-wcsnlen-nonarray.
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit 783d4c0b81889c39a9ddf13b60d0fde4040fb1c0)
diff --git a/string/Makefile b/string/Makefile
index 8f31fa49e621c035..2e20fc00fdd8d607 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -184,6 +184,7 @@ tests := \
test-strncpy \
test-strndup \
test-strnlen \
+ test-strnlen-nonarray \
test-strpbrk \
test-strrchr \
test-strspn \
diff --git a/string/test-Xnlen-nonarray.c b/string/test-Xnlen-nonarray.c
new file mode 100644
index 0000000000000000..499bef2041ac4ae1
--- /dev/null
+++ b/string/test-Xnlen-nonarray.c
@@ -0,0 +1,133 @@
+/* Test non-array inputs to string length functions.
+ Copyright (C) 2024 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/>. */
+
+/* This skeleton file is included from string/test-strnlen-nonarray.c
+ and wcsmbs/test-wcsnlen-nonarray.c to test that reading of the array
+ stops at the first null character.
+
+ TEST_IDENTIFIER must be the test function identifier. TEST_NAME is
+ the same as a string.
+
+ CHAR must be defined as the character type. */
+
+#include <array_length.h>
+#include <string.h>
+#include <support/check.h>
+#include <support/next_to_fault.h>
+#include <support/test-driver.h>
+#include <sys/param.h>
+#include <unistd.h>
+
+typedef __typeof (TEST_IDENTIFIER) *proto_t;
+
+#define TEST_MAIN
+#include "test-string.h"
+
+IMPL (TEST_IDENTIFIER, 1)
+
+static int
+test_main (void)
+{
+ enum { buffer_length = 256 };
+ TEST_VERIFY_EXIT (sysconf (_SC_PAGESIZE) >= buffer_length);
+
+ test_init ();
+
+ /* Buffer layout: There are a_count 'A' character followed by
+ zero_count null character, for a total of buffer_length
+ character:
+
+ AAAAA...AAAAA 00000 ... 00000 (unmapped page follows)
+ \ / \ /
+ (a_count) (zero_count)
+ \___ (buffer_length) ___/
+ ^
+ |
+ start_offset
+
+ The buffer length does not change, but a_count (and thus _zero)
+ and start_offset vary.
+
+ If start_offset == buffer_length, only 0 is a valid length
+ argument. The result is 0.
+
+ Otherwwise, if zero_count > 0 (if there a null characters in the
+ buffer), then any length argument is valid. If start_offset <
+ a_count (i.e., there is a non-null character at start_offset), the
+ result is the minimum of a_count - start_offset and the length
+ argument. Otherwise the result is 0.
+
+ Otherwise, there are no null characters before the unmapped page.
+ The length argument must not be greater than buffer_length -
+ start_offset, and the result is the length argument. */
+
+ struct support_next_to_fault ntf
+ = support_next_to_fault_allocate (buffer_length * sizeof (CHAR));
+ CHAR *buffer = (CHAR *) ntf.buffer;
+
+ FOR_EACH_IMPL (impl, 0)
+ {
+ printf ("info: testing %s\n", impl->name);
+ for (size_t i = 0; i < buffer_length; ++i)
+ buffer[i] = 'A';
+
+ for (int zero_count = 0; zero_count <= buffer_length; ++zero_count)
+ {
+ if (zero_count > 0)
+ buffer[buffer_length - zero_count] = 0;
+ int a_count = buffer_length - zero_count;
+ for (int start_offset = 0; start_offset <= buffer_length;
+ ++start_offset)
+ {
+ CHAR *start_pointer = buffer + start_offset;
+ if (start_offset == buffer_length)
+ TEST_COMPARE (CALL (impl, buffer + start_offset, 0), 0);
+ else if (zero_count > 0)
+ for (int length_argument = 0;
+ length_argument <= 2 * buffer_length;
+ ++length_argument)
+ {
+ if (test_verbose)
+ printf ("zero_count=%d a_count=%d start_offset=%d"
+ " length_argument=%d\n",
+ zero_count, a_count, start_offset,
+ length_argument);
+ if (start_offset < a_count)
+ TEST_COMPARE (CALL (impl, start_pointer, length_argument),
+ MIN (a_count - start_offset,
+ length_argument));
+ else
+ TEST_COMPARE (CALL (impl, start_pointer, length_argument),
+ 0);
+ }
+ else
+ for (int length_argument = 0;
+ length_argument <= buffer_length - start_offset;
+ ++length_argument)
+ TEST_COMPARE (CALL (impl, start_pointer, length_argument),
+ length_argument);
+ }
+ }
+ }
+
+ support_next_to_fault_free (&ntf);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/string/test-strnlen-nonarray.c b/string/test-strnlen-nonarray.c
new file mode 100644
index 0000000000000000..0ad05756d9a31a3d
--- /dev/null
+++ b/string/test-strnlen-nonarray.c
@@ -0,0 +1,4 @@
+#define TEST_IDENTIFIER strnlen
+#define TEST_NAME "strnlen"
+typedef char CHAR;
+#include "test-Xnlen-nonarray.c"
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
index 65173e28aabf9f85..23da6f0eed55d543 100644
--- a/wcsmbs/Makefile
+++ b/wcsmbs/Makefile
@@ -160,6 +160,7 @@ tests := \
test-wcsncmp \
test-wcsncpy \
test-wcsnlen \
+ test-wcsnlen-nonarray \
test-wcspbrk \
test-wcsrchr \
test-wcsspn \
diff --git a/wcsmbs/test-wcsnlen-nonarray.c b/wcsmbs/test-wcsnlen-nonarray.c
new file mode 100644
index 0000000000000000..a4b21fecd388448a
--- /dev/null
+++ b/wcsmbs/test-wcsnlen-nonarray.c
@@ -0,0 +1,5 @@
+#include <wchar.h>
+#define TEST_IDENTIFIER wcsnlen
+#define TEST_NAME "wcsnlen"
+typedef wchar_t CHAR;
+#include "../string/test-Xnlen-nonarray.c"