glibc/debug
Joan Bruguera ca0faa140f 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 18:44:27 +05:30
..
asprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
backtrace-tst.c
backtrace.c backtrace: Implement on top of <unwind-link.h> 2021-03-01 15:58:28 +01:00
backtracesyms.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
backtracesymsfd.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
catchsegv.sh Update copyright dates not handled by scripts/update-copyrights. 2021-01-02 12:17:34 -08:00
chk_fail.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
confstr_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
Depend
dprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
execinfo.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
explicit_bzero_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
fdelt_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
fgets_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
fgets_u_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
fgetws_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
fgetws_u_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
fortify_fail.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
fprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
fread_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
fread_u_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
fwprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
getcwd_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
getdomainname_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
getgroups_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
gethostname_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
gets_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
getwd_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
longjmp_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
Makefile debug: Synchronize feature guards in fortified functions [BZ #28746] 2022-03-11 20:36:24 +05:30
mbsnrtowcs_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
mbsrtowcs_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
mbstowcs_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
memcpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
memmove_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
mempcpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
memset_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
noophooks.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
obprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
pcprofile.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
pcprofiledump.c Update copyright dates not handled by scripts/update-copyrights. 2021-01-02 12:17:34 -08:00
poll_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
ppoll_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
pread64_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
pread_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
printf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
read_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
readlink_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
readlinkat_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
readonly-area.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
realpath_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
recv_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
recvfrom_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
segfault.c libSegFault: Fix printing signal number [BZ #27249] 2021-02-01 20:04:08 +00:00
snprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
sprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
stack_chk_fail_local.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
stack_chk_fail.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
stpcpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
stpncpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
strcat_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
strcpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
strncat_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
strncpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
swprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-stpcpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-strcpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-backtrace2.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-backtrace3.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-backtrace4.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-backtrace5.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-backtrace6.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-backtrace.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-fortify.c misc: Fix rare fortify crash on wchar funcs. [BZ 29030] 2022-04-25 18:44:27 +05:30
tst-longjmp_chk2.c test-skeleton.c: Add write_message function 2016-06-23 11:00:36 +02:00
tst-longjmp_chk3.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-longjmp_chk.c
tst-realpath-chk.c fortify: Fix spurious warning with realpath 2022-03-11 20:36:24 +05:30
tst-ssp-1.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
ttyname_r_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
vasprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
vdprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
Versions New string function explicit_bzero (from OpenBSD). 2016-12-16 16:21:54 -05:00
vfprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
vfwprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
vobprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
vprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
vsnprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
vsprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
vswprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
vwprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcpcpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcpncpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcrtomb_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcscat_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcscpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcsncat_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcsncpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcsnrtombs_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcsrtombs_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcstombs_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wctomb_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wmemcpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wmemmove_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wmempcpy_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wmemset_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wprintf_chk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
xtrace.sh Remove all usage of @BASH@ or ${BASH} in installed files, and hardcode /bin/bash instead 2021-05-12 07:47:11 +05:30