diff options
49 files changed, 563 insertions, 0 deletions
diff --git a/debug/Makefile b/debug/Makefile index 55e2aadec9..9d658e3002 100644 --- a/debug/Makefile +++ b/debug/Makefile @@ -105,6 +105,8 @@ routines = \ wcrtomb_chk \ wcscat_chk \ wcscpy_chk \ + wcslcat_chk \ + wcslcpy_chk \ wcsncat_chk \ wcsncpy_chk \ wcsnrtombs_chk \ diff --git a/debug/Versions b/debug/Versions index 94dfa5f428..9cf2725992 100644 --- a/debug/Versions +++ b/debug/Versions @@ -61,6 +61,8 @@ libc { GLIBC_2.38 { __strlcat_chk; __strlcpy_chk; + __wcslcat_chk; + __wcslcpy_chk; } GLIBC_PRIVATE { __fortify_fail; diff --git a/debug/tst-fortify.c b/debug/tst-fortify.c index 0f823a85d0..3744aadad4 100644 --- a/debug/tst-fortify.c +++ b/debug/tst-fortify.c @@ -783,6 +783,18 @@ do_test (void) CHK_FAIL_END CHK_FAIL_START + wcslcpy (wbuf + 7, L"X", 4); + CHK_FAIL_END + + CHK_FAIL_START + wcslcpy (wbuf + 7, L"X", l0 + 4); + CHK_FAIL_END + + CHK_FAIL_START + wcslcpy (wbuf + 9, L"XABCDEFGH", 8); + CHK_FAIL_END + + CHK_FAIL_START wcpncpy (wbuf + 9, L"XABCDEFGH", 8); CHK_FAIL_END @@ -804,6 +816,11 @@ do_test (void) wcsncat (wbuf, L"ZYXWV", l0 + 3); CHK_FAIL_END + wmemcpy (wbuf, wstr1 + 4, 7); + CHK_FAIL_START + wcslcat (wbuf, L"ZYXWV", l0 + 11); + CHK_FAIL_END + CHK_FAIL_START wmemcpy (wa.buf1 + 1, L"abcdefghij", 10); CHK_FAIL_END diff --git a/debug/wcslcat_chk.c b/debug/wcslcat_chk.c new file mode 100644 index 0000000000..8ddcc012b1 --- /dev/null +++ b/debug/wcslcat_chk.c @@ -0,0 +1,31 @@ +/* Fortified version of wcslcat. + Copyright (C) 2023 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 <wchar.h> + +/* Check that the user-supplied size does not exceed the + compiler-determined size, and then forward to wcslcat. */ +size_t +__wcslcat_chk (wchar_t *__restrict s1, const wchar_t *__restrict s2, + size_t n, size_t s1len) +{ + if (__glibc_unlikely (s1len < n)) + __chk_fail (); + + return __wcslcat (s1, s2, n); +} diff --git a/debug/wcslcpy_chk.c b/debug/wcslcpy_chk.c new file mode 100644 index 0000000000..077fa3715f --- /dev/null +++ b/debug/wcslcpy_chk.c @@ -0,0 +1,31 @@ +/* Fortified version of wcslcpy. + Copyright (C) 2023 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 <wchar.h> + +/* Check that the user-supplied size does not exceed the + compiler-determined size, and then forward to wcslcpy. */ +size_t +__wcslcpy_chk (wchar_t *__restrict s1, const wchar_t *__restrict s2, + size_t n, size_t s1len) +{ + if (__glibc_unlikely (s1len < n)) + __chk_fail (); + + return __wcslcpy (s1, s2, n); +} diff --git a/include/wchar.h b/include/wchar.h index fafe7c8e9b..ff4ae52045 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -203,6 +203,8 @@ extern size_t __wcslen (const wchar_t *__s) __attribute_pure__; extern size_t __wcsnlen (const wchar_t *__s, size_t __maxlen) __attribute_pure__; extern wchar_t *__wcscat (wchar_t *dest, const wchar_t *src); +extern __typeof (wcslcat) __wcslcat; +libc_hidden_proto (__wcslcat) extern wint_t __btowc (int __c) attribute_hidden; extern int __mbsinit (const __mbstate_t *__ps); extern size_t __mbrtowc (wchar_t *__restrict __pwc, @@ -237,8 +239,11 @@ extern wchar_t *__wcscpy (wchar_t *__restrict __dest, const wchar_t *__restrict __src) attribute_hidden __nonnull ((1, 2)); libc_hidden_proto (__wcscpy) +extern __typeof (wcslcpy) __wcslcpy; +libc_hidden_proto (__wcslcpy) extern wchar_t *__wcsncpy (wchar_t *__restrict __dest, const wchar_t *__restrict __src, size_t __n); + extern wchar_t *__wcpcpy (wchar_t *__dest, const wchar_t *__src); extern wchar_t *__wcpncpy (wchar_t *__dest, const wchar_t *__src, size_t __n); diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist index 9b4c5f4719..74a9f427b2 100644 --- a/sysdeps/mach/hurd/i386/libc.abilist +++ b/sysdeps/mach/hurd/i386/libc.abilist @@ -2328,8 +2328,12 @@ GLIBC_2.38 __isoc23_wcstoumax F GLIBC_2.38 __isoc23_wscanf F GLIBC_2.38 __strlcat_chk F GLIBC_2.38 __strlcpy_chk F +GLIBC_2.38 __wcslcat_chk F +GLIBC_2.38 __wcslcpy_chk F GLIBC_2.38 strlcat F GLIBC_2.38 strlcpy F +GLIBC_2.38 wcslcat F +GLIBC_2.38 wcslcpy F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist index cf51b88932..c49363e70e 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist +++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist @@ -2667,5 +2667,9 @@ GLIBC_2.38 __isoc23_wcstoumax F GLIBC_2.38 __isoc23_wscanf F GLIBC_2.38 __strlcat_chk F GLIBC_2.38 __strlcpy_chk F +GLIBC_2.38 __wcslcat_chk F +GLIBC_2.38 __wcslcpy_chk F GLIBC_2.38 strlcat F GLIBC_2.38 strlcpy F +GLIBC_2.38 wcslcat F +GLIBC_2.38 wcslcpy F diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist index 4b25f343b8..d6b1dcaae6 100644 --- a/sysdeps/unix/sysv/linux/alpha/libc.abilist +++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist @@ -2776,8 +2776,12 @@ GLIBC_2.38 __nldbl___isoc23_vwscanf F GLIBC_2.38 __nldbl___isoc23_wscanf F GLIBC_2.38 __strlcat_chk F GLIBC_2.38 __strlcpy_chk F +GLIBC_2.38 __wcslcat_chk F +GLIBC_2.38 __wcslcpy_chk F GLIBC_2.38 strlcat F GLIBC_2.38 strlcpy F +GLIBC_2.38 wcslcat F +GLIBC_2.38 wcslcpy F GLIBC_2.4 _IO_fprintf F GLIBC_2.4 _IO_printf F GLIBC_2.4 _IO_sprintf F diff --git a/sysdeps/unix/sysv/linux/arc/libc.abilist b/sysdeps/unix/sysv/linux/arc/libc.abilist index 5a58cc0477..dfe0c3f7b6 100644 --- a/sysdeps/unix/sysv/linux/arc/libc.abilist +++ b/sysdeps/unix/sysv/linux/arc/libc.abilist @@ -2428,5 +2428,9 @@ GLIBC_2.38 __isoc23_wcstoumax F GLIBC_2.38 __isoc23_wscanf F GLIBC_2.38 __strlcat_chk F GLIBC_2.38 __strlcpy_chk F +GLIBC_2.38 __wcslcat_chk F +GLIBC_2.38 __wcslcpy_chk F GLIBC_2.38 strlcat F GLIBC_2.38 strlcpy F +GLIBC_2.38 wcslcat F +GLIBC_2.38 wcslcpy F diff --git a/sysdeps/unix/sysv/linux/arm/be/libc.abilist b/sysdeps/unix/sysv/linux/arm/be/libc.abilist index 99ce948c5c..6c75e5aa76 100644 --- a/sysdeps/unix/sysv/linux/arm/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/be/libc.abilist @@ -548,8 +548,12 @@ GLIBC_2.38 __isoc23_wcstoumax F GLIBC_2.38 __isoc23_wscanf F GLIBC_2.38 __strlcat_chk F GLIBC_2.38 __strlcpy_chk F +GLIBC_2.38 __wcslcat_chk F +GLIBC_2.38 __wcslcpy_chk F GLIBC_2.38 strlcat F GLIBC_2.38 strlcpy F +GLIBC_2.38 wcslcat F +GLIBC_2.38 wcslcpy F GLIBC_2.4 _Exit F GLIBC_2.4 _IO_2_1_stderr_ D 0xa0 GLIBC_2.4 _IO_2_1_stdin_ D 0xa0 diff --git a/sysdeps/unix/sysv/linux/arm/le/libc.abilist b/sysdeps/unix/sysv/linux/arm/le/libc.abilist index c00bf72ebc..03d6f7ae2d 100644 --- a/sysdeps/unix/sysv/linux/arm/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/le/libc.abilist @@ -545,8 +545,12 @@ GLIBC_2.38 __isoc23_wcstoumax F GLIBC_2.38 __isoc23_wscanf F GLIBC_2.38 __strlcat_chk F GLIBC_2.38 __strlcpy_chk F +GLIBC_2.38 __wcslcat_chk F +GLIBC_2.38 __wcslcpy_chk F GLIBC_2.38 strlcat F GLIBC_2.38 strlcpy F +GLIBC_2.38 wcslcat F +GLIBC_2.38 wcslcpy F GLIBC_2.4 _Exit F GLIBC_2.4 _IO_2_1_stderr_ D 0xa0 GLIBC_2.4 _IO_2_1_stdin_ D 0xa0 diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist index 71130f2c6b..d858c108c6 100644 --- a/sysdeps/unix/sysv/linux/csky/libc.abilist +++ b/sysdeps/unix/sysv/linux/csky/libc.abilist @@ -2704,5 +2704,9 @@ GLIBC_2.38 __isoc23_wcstoumax F GLIBC_2.38 __isoc23_wscanf F GLIBC_2.38 __strlcat_chk F GLIBC_2.38 __strlcpy_chk F +GLIBC_2.38 __wcslcat_chk F +GLIBC_2.38 __wcslcpy_chk F GLIBC_2.38 strlcat F GLIBC_2.38 strlcpy F +GLIBC_2.38 wcslcat F +GLIBC_2.38 wcslcpy F diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist index 5a651c03df..82a14f8ace 100644 --- a/sysdeps/unix/sysv/linux/hppa/libc.abilist +++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist @@ -2653,8 +2653,12 @@ GLIBC_2.38 __isoc23_wcstoumax F GLIBC_2.38 __isoc23_wscanf F GLIBC_2.38 __strlcat_chk F GLIBC_2.38 __strlcpy_chk F +GLIBC_2.38 __wcslcat_chk F +GLIBC_2.38 __wcslcpy_chk F GLIBC_2.38 strlcat F GLIBC_2.38 strlcpy F +GLIBC_2.38 wcslcat F +GLIBC_2.38 wcslcpy F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist index 12b91ef632..1950b15d5d 100644 --- a/sysdeps/unix/sysv/linux/i386/libc.abilist +++ b/sysdeps/unix/sysv/linux/i386/libc.abilist @@ -2837,8 +2837,12 @@ GLIBC_2.38 __isoc23_wcstoumax F GLIBC_2.38 __isoc23_wscanf F GLIBC_2.38 __strlcat_chk F GLIBC_2.38 __strlcpy_chk F +GLIBC_2.38 __wcslcat_chk F +GLIBC_2.38 __wcslcpy_chk F GLIBC_2.38 strlcat F GLIBC_2.38 strlcpy F +GLIBC_2.38 wcslcat F +GLIBC_2.38 wcslcpy F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist index f223c5e08d..d0b9cb279b 100644 --- a/sysdeps/unix/sysv/linux/ia64/libc.abilist +++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist @@ -2602,8 +2602,12 @@ GLIBC_2.38 __isoc23_wcstoumax F GLIBC_2.38 __isoc23_wscanf F GLIBC_2.38 __strlcat_chk F GLIBC_2.38 __strlcpy_chk F +GLIBC_2.38 __wcslcat_chk F |
