Go to file
Joan Bruguera c8ee1c85c0 misc: Fix rare fortify crash on wchar funcs. [BZ 29030]
If `__glibc_objsize (__o) == (size_t) -1` (i.e. `__o` is unknown size), fortify
checks should pass, and `__whatever_alias` should be called.

Previously, `__glibc_objsize (__o) == (size_t) -1` was explicitly checked, but
on commit a643f60c53, this was moved into `__glibc_safe_or_unknown_len`.

A comment says the -1 case should work as: "The -1 check is redundant because
since it implies that __glibc_safe_len_cond is true.". But this fails when:
* `__s > 1`
* `__osz == -1` (i.e. unknown size at compile time)
* `__l` is big enough
* `__l * __s <= __osz` can be folded to a constant
(I only found this to be true for `mbsrtowcs` and other functions in wchar2.h)

In this case `__l * __s <= __osz` is false, and `__whatever_chk_warn` will be
called by `__glibc_fortify` or `__glibc_fortify_n` and crash the program.

This commit adds the explicit `__osz == -1` check again.
moc crashes on startup due to this, see: https://bugs.archlinux.org/task/74041

Minimal test case (test.c):
    #include <wchar.h>

    int main (void)
    {
        const char *hw = "HelloWorld";
        mbsrtowcs (NULL, &hw, (size_t)-1, NULL);
        return 0;
    }

Build with:
    gcc -O2 -Wp,-D_FORTIFY_SOURCE=2 test.c -o test && ./test

Output:
    *** buffer overflow detected ***: terminated

Fixes: BZ #29030
Signed-off-by: Joan Bruguera <joanbrugueram@gmail.com>
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit 33e03f9cd2)
2022-04-25 17:37:17 +05:30
argp
assert
benchtests
bits elf: Issue la_symbind for bind-now (BZ #23734) 2022-02-01 14:49:46 -03:00
catgets
ChangeLog.old Create ChangeLog.old/ChangeLog.24. 2022-02-03 00:27:54 -05:00
conform
crypt
csu
ctype
debug misc: Fix rare fortify crash on wchar funcs. [BZ 29030] 2022-04-25 17:37:17 +05:30
dirent
dlfcn
elf Default to --with-default-link=no (bug 25812) 2022-04-22 11:27:52 +02:00
gmon
gnulib
grp
gshadow
hesiod
htl
hurd
iconv
iconvdata
include Prepare for glibc 2.35 release. 2022-02-03 00:23:26 -05:00
inet
intl
io io: Add fsync call in tst-stat 2022-03-11 10:16:06 +01:00
libio
locale localedef: Handle symbolic links when generating locale-archive 2022-03-03 11:57:30 +01:00
localedata localedata: Do not generate output if warnings were present. 2022-02-25 08:54:16 -05:00
login
mach
malloc malloc: Fix tst-mallocalign1 macro spacing. 2022-02-01 11:05:26 -05:00
manual Default to --with-default-link=no (bug 25812) 2022-04-22 11:27:52 +02:00
math
mathvec
misc misc: Fix rare fortify crash on wchar funcs. [BZ 29030] 2022-04-25 17:37:17 +05:30
nis
nptl nptl: Fix pthread_cancel cancelhandling atomic operations 2022-04-20 13:42:28 -03:00
nptl_db
nscd
nss hurd: Fix arbitrary error code 2022-04-18 17:54:19 +02:00
po Update translations. 2022-02-02 23:30:15 -05:00
posix posix: Fix tst-spawn6 terminal handling (BZ #28853) 2022-02-03 08:13:57 -03:00
pwd
resolv resolv: Fix tst-resolv tests for 2.35 ABIs and later 2022-02-24 16:28:30 +09:00
resource
rt
scripts scripts: Add glibcelf.py module 2022-04-22 11:00:43 +02:00
setjmp
shadow
signal
socket
soft-fp
stdio-common
stdlib stdlib: Avoid -Wuse-after-free in __add_to_environ [BZ #26779] 2022-01-25 17:39:36 -07:00
string string: Add a testcase for wcsncmp with SIZE_MAX [BZ #28755] 2022-02-17 11:09:52 -08:00
sunrpc
support support: Add support_socket_so_timestamp_time64 2022-01-28 17:46:43 -03:00
sysdeps Default to --with-default-link=no (bug 25812) 2022-04-22 11:27:52 +02:00
sysvipc
termios
time
timezone
wcsmbs
wctype
.gitattributes
.gitignore
abi-tags
aclocal.m4
config.h.in
config.make.in
configure Default to --with-default-link=no (bug 25812) 2022-04-22 11:27:52 +02:00
configure.ac Default to --with-default-link=no (bug 25812) 2022-04-22 11:27:52 +02:00
CONTRIBUTED-BY
COPYING
COPYING.LIB
extra-lib.mk
gen-locales.mk
INSTALL Default to --with-default-link=no (bug 25812) 2022-04-22 11:27:52 +02:00
libc-abis
libof-iterator.mk
LICENSES
MAINTAINERS
Makeconfig
Makefile
Makefile.help
Makefile.in
Makerules
NEWS Default to --with-default-link=no (bug 25812) 2022-04-22 11:27:52 +02:00
o-iterator.mk
README
Rules
SHARED-FILES
shlib-versions nss: Do not mention NSS test modules in <gnu/lib-names.h> 2022-03-11 10:16:11 +01:00
test-skeleton.c
version.h Prepare for glibc 2.35 release. 2022-02-03 00:23:26 -05:00

This directory contains the sources of the GNU C Library.
See the file "version.h" for what release version you have.

The GNU C Library is the standard system C library for all GNU systems,
and is an important part of what makes up a GNU system.  It provides the
system API for all programs written in C and C-compatible languages such
as C++ and Objective C; the runtime facilities of other programming
languages use the C library to access the underlying operating system.

In GNU/Linux systems, the C library works with the Linux kernel to
implement the operating system behavior seen by user applications.
In GNU/Hurd systems, it works with a microkernel and Hurd servers.

The GNU C Library implements much of the POSIX.1 functionality in the
GNU/Hurd system, using configurations i[4567]86-*-gnu.

When working with Linux kernels, this version of the GNU C Library
requires Linux kernel version 3.2 or later.

Also note that the shared version of the libgcc_s library must be
installed for the pthread library to work correctly.

The GNU C Library supports these configurations for using Linux kernels:

	aarch64*-*-linux-gnu
	alpha*-*-linux-gnu
	arc*-*-linux-gnu
	arm-*-linux-gnueabi
	csky-*-linux-gnuabiv2
	hppa-*-linux-gnu
	i[4567]86-*-linux-gnu
	x86_64-*-linux-gnu	Can build either x86_64 or x32
	ia64-*-linux-gnu
	m68k-*-linux-gnu
	microblaze*-*-linux-gnu
	mips-*-linux-gnu
	mips64-*-linux-gnu
	or1k-*-linux-gnu
	powerpc-*-linux-gnu	Hardware or software floating point, BE only.
	powerpc64*-*-linux-gnu	Big-endian and little-endian.
	s390-*-linux-gnu
	s390x-*-linux-gnu
	riscv32-*-linux-gnu
	riscv64-*-linux-gnu
	sh[34]-*-linux-gnu
	sparc*-*-linux-gnu
	sparc64*-*-linux-gnu

If you are interested in doing a port, please contact the glibc
maintainers; see https://www.gnu.org/software/libc/ for more
information.

See the file INSTALL to find out how to configure, build, and install
the GNU C Library.  You might also consider reading the WWW pages for
the C library at https://www.gnu.org/software/libc/.

The GNU C Library is (almost) completely documented by the Texinfo manual
found in the `manual/' subdirectory.  The manual is still being updated
and contains some known errors and omissions; we regret that we do not
have the resources to work on the manual as much as we would like.  For
corrections to the manual, please file a bug in the `manual' component,
following the bug-reporting instructions below.  Please be sure to check
the manual in the current development sources to see if your problem has
already been corrected.

Please see https://www.gnu.org/software/libc/bugs.html for bug reporting
information.  We are now using the Bugzilla system to track all bug reports.
This web page gives detailed information on how to report bugs properly.

The GNU C Library is free software.  See the file COPYING.LIB for copying
conditions, and LICENSES for notices about a few contributions that require
these additional notices to be distributed.  License copyright years may be
listed using range notation, e.g., 1996-2015, indicating that every year in
the range, inclusive, is a copyrightable year that would otherwise be listed
individually.