diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-12-27 15:26:46 +0000 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-12-27 15:26:46 +0000 |
commit | df6d86d8822458cf787b5f5620490d6a962da3b8 (patch) | |
tree | 8d499fa24a32a195bd6e384dfb70639c45c4a9bb /debug | |
parent | 2c7242b971fd7b63fa842df15ec6fa3d0ff8aeb0 (diff) | |
parent | 1949a12d5da678a8532359a95717d8e63910d93b (diff) |
Merge commit 'refs/top-bases/t/____longjmp_chk' into t/____longjmp_chkt/____longjmp_chk
Diffstat (limited to 'debug')
104 files changed, 567 insertions, 305 deletions
diff --git a/debug/Makefile b/debug/Makefile index 6b5f31e4f6..506cebc3c4 100644 --- a/debug/Makefile +++ b/debug/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1998-2016 Free Software Foundation, Inc. +# Copyright (C) 1998-2018 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 @@ -48,69 +48,84 @@ routines = backtrace backtracesyms backtracesymsfd noophooks \ vdprintf_chk obprintf_chk \ longjmp_chk ____longjmp_chk \ fdelt_chk poll_chk ppoll_chk \ + explicit_bzero_chk \ stack_chk_fail fortify_fail \ $(static-only-routines) static-only-routines := warning-nop stack_chk_fail_local -CFLAGS-backtrace.c = -fno-omit-frame-pointer -CFLAGS-sprintf_chk.c = $(libio-mtsafe) -CFLAGS-snprintf_chk.c = $(libio-mtsafe) -CFLAGS-vsprintf_chk.c = $(libio-mtsafe) -CFLAGS-vsnprintf_chk.c = $(libio-mtsafe) -CFLAGS-asprintf_chk.c = $(libio-mtsafe) -CFLAGS-vasprintf_chk.c = $(libio-mtsafe) -CFLAGS-obprintf_chk.c = $(libio-mtsafe) -CFLAGS-dprintf_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-vdprintf_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-printf_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-fprintf_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-vprintf_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-vfprintf_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-gets_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-fgets_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-fgets_u_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-fread_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-fread_u_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-swprintf_chk.c = $(libio-mtsafe) -CFLAGS-vswprintf_chk.c = $(libio-mtsafe) -CFLAGS-wprintf_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-fwprintf_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-vwprintf_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-vfwprintf_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-fgetws_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-fgetws_u_chk.c = $(libio-mtsafe) -fexceptions -CFLAGS-read_chk.c = -fexceptions -fasynchronous-unwind-tables -CFLAGS-pread_chk.c = -fexceptions -fasynchronous-unwind-tables -CFLAGS-pread64_chk.c = -fexceptions -fasynchronous-unwind-tables -CFLAGS-recv_chk.c = -fexceptions -fasynchronous-unwind-tables -CFLAGS-recvfrom_chk.c = -fexceptions -fasynchronous-unwind-tables +# Don't add stack_chk_fail_local.o to libc.a since __stack_chk_fail_local +# is an alias of __stack_chk_fail in stack_chk_fail.o. +elide-routines.o := stack_chk_fail_local + +# Building the stack-protector failure routines with stack protection +# is not required since we have already failed a stack check and are +# exiting the process. However, the local aliases which jump to the +# real routines should still be compiled with stack protection +# (stack_chk_fail_local.c), so that the statically linked parts of the +# library have the expected flags. + +CFLAGS-stack_chk_fail.c += $(no-stack-protector) + +CFLAGS-backtrace.c += -fno-omit-frame-pointer -funwind-tables +CFLAGS-sprintf_chk.c += $(libio-mtsafe) +CFLAGS-snprintf_chk.c += $(libio-mtsafe) +CFLAGS-vsprintf_chk.c += $(libio-mtsafe) +CFLAGS-vsnprintf_chk.c += $(libio-mtsafe) +CFLAGS-asprintf_chk.c += $(libio-mtsafe) +CFLAGS-vasprintf_chk.c += $(libio-mtsafe) +CFLAGS-obprintf_chk.c += $(libio-mtsafe) +CFLAGS-dprintf_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-vdprintf_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-printf_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-fprintf_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-vprintf_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-vfprintf_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-gets_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-fgets_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-fgets_u_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-fread_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-fread_u_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-swprintf_chk.c += $(libio-mtsafe) +CFLAGS-vswprintf_chk.c += $(libio-mtsafe) +CFLAGS-wprintf_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-fwprintf_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-vwprintf_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-vfwprintf_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-fgetws_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-fgetws_u_chk.c += $(libio-mtsafe) -fexceptions +CFLAGS-read_chk.c += -fexceptions -fasynchronous-unwind-tables +CFLAGS-pread_chk.c += -fexceptions -fasynchronous-unwind-tables +CFLAGS-pread64_chk.c += -fexceptions -fasynchronous-unwind-tables +CFLAGS-recv_chk.c += -fexceptions -fasynchronous-unwind-tables +CFLAGS-recvfrom_chk.c += -fexceptions -fasynchronous-unwind-tables # Need to make sure the settings here override what configure might have # set up for us, so keep the CFLAGS/CPPFLAGS split logical as the order is: # <user CFLAGS> <test CFLAGS> <user CPPFLAGS> <test CPPFLAGS> -CFLAGS-tst-longjmp_chk.c = -fexceptions -fasynchronous-unwind-tables -CPPFLAGS-tst-longjmp_chk.c = -D_FORTIFY_SOURCE=1 -CFLAGS-tst-longjmp_chk2.c = -fexceptions -fasynchronous-unwind-tables -CPPFLAGS-tst-longjmp_chk2.c = -D_FORTIFY_SOURCE=1 -CFLAGS-tst-longjmp_chk3.c = -fexceptions -fasynchronous-unwind-tables -CPPFLAGS-tst-longjmp_chk3.c = -D_FORTIFY_SOURCE=1 +CFLAGS-tst-longjmp_chk.c += -fexceptions -fasynchronous-unwind-tables +CPPFLAGS-tst-longjmp_chk.c += -D_FORTIFY_SOURCE=1 +CFLAGS-tst-longjmp_chk2.c += -fexceptions -fasynchronous-unwind-tables +CPPFLAGS-tst-longjmp_chk2.c += -D_FORTIFY_SOURCE=1 +CFLAGS-tst-longjmp_chk3.c += -fexceptions -fasynchronous-unwind-tables +CPPFLAGS-tst-longjmp_chk3.c += -D_FORTIFY_SOURCE=1 # We know these tests have problems with format strings, this is what -# we are testing. Disable that warning. They also generate warnings -# from warning attributes, which cannot be disabled via pragmas, so -# require -Wno-error to be used. -CFLAGS-tst-chk1.c = -Wno-format -Wno-error -CFLAGS-tst-chk2.c = -Wno-format -Wno-error -CFLAGS-tst-chk3.c = -Wno-format -Wno-error -CFLAGS-tst-chk4.cc = -Wno-format -Wno-error -CFLAGS-tst-chk5.cc = -Wno-format -Wno-error -CFLAGS-tst-chk6.cc = -Wno-format -Wno-error -CFLAGS-tst-lfschk1.c = -Wno-format -Wno-error -CFLAGS-tst-lfschk2.c = -Wno-format -Wno-error -CFLAGS-tst-lfschk3.c = -Wno-format -Wno-error -CFLAGS-tst-lfschk4.cc = -Wno-format -Wno-error -CFLAGS-tst-lfschk5.cc = -Wno-format -Wno-error -CFLAGS-tst-lfschk6.cc = -Wno-format -Wno-error +# we are testing. Disable that warning. They are also testing +# deprecated functions (notably gets) so disable that warning as well. +# And they also generate warnings from warning attributes, which +# cannot be disabled via pragmas, so require -Wno-error to be used. +CFLAGS-tst-chk1.c += -Wno-format -Wno-deprecated-declarations -Wno-error +CFLAGS-tst-chk2.c += -Wno-format -Wno-deprecated-declarations -Wno-error +CFLAGS-tst-chk3.c += -Wno-format -Wno-deprecated-declarations -Wno-error +CFLAGS-tst-chk4.cc += -Wno-format -Wno-deprecated-declarations -Wno-error +CFLAGS-tst-chk5.cc += -Wno-format -Wno-deprecated-declarations -Wno-error +CFLAGS-tst-chk6.cc += -Wno-format -Wno-deprecated-declarations -Wno-error +CFLAGS-tst-lfschk1.c += -Wno-format -Wno-deprecated-declarations -Wno-error +CFLAGS-tst-lfschk2.c += -Wno-format -Wno-deprecated-declarations -Wno-error +CFLAGS-tst-lfschk3.c += -Wno-format -Wno-deprecated-declarations -Wno-error +CFLAGS-tst-lfschk4.cc += -Wno-format -Wno-deprecated-declarations -Wno-error +CFLAGS-tst-lfschk5.cc += -Wno-format -Wno-deprecated-declarations -Wno-error +CFLAGS-tst-lfschk6.cc += -Wno-format -Wno-deprecated-declarations -Wno-error LDLIBS-tst-chk4 = -lstdc++ LDLIBS-tst-chk5 = -lstdc++ LDLIBS-tst-chk6 = -lstdc++ @@ -131,12 +146,18 @@ LDFLAGS-tst-backtrace4 = -rdynamic LDFLAGS-tst-backtrace5 = -rdynamic LDFLAGS-tst-backtrace6 = -rdynamic +CFLAGS-tst-ssp-1.c += -fstack-protector-all + tests = backtrace-tst tst-longjmp_chk tst-chk1 tst-chk2 tst-chk3 \ tst-lfschk1 tst-lfschk2 tst-lfschk3 test-strcpy_chk test-stpcpy_chk \ tst-chk4 tst-chk5 tst-chk6 tst-lfschk4 tst-lfschk5 tst-lfschk6 \ tst-longjmp_chk2 tst-backtrace2 tst-backtrace3 tst-backtrace4 \ tst-backtrace5 tst-backtrace6 +ifeq ($(have-ssp),yes) +tests += tst-ssp-1 +endif + ifeq (,$(CXX)) tests-unsupported = tst-chk4 tst-chk5 tst-chk6 \ tst-lfschk4 tst-lfschk5 tst-lfschk6 diff --git a/debug/Versions b/debug/Versions index 0482c85f19..a6628db356 100644 --- a/debug/Versions +++ b/debug/Versions @@ -55,6 +55,9 @@ libc { GLIBC_2.16 { __poll_chk; __ppoll_chk; } + GLIBC_2.25 { + __explicit_bzero_chk; + } GLIBC_PRIVATE { __fortify_fail; } diff --git a/debug/asprintf_chk.c b/debug/asprintf_chk.c index 4e0bf7912f..9cd4143f2e 100644 --- a/debug/asprintf_chk.c +++ b/debug/asprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/backtrace.c b/debug/backtrace.c index c01b9585c7..d423cc053a 100644 --- a/debug/backtrace.c +++ b/debug/backtrace.c @@ -1,7 +1,7 @@ -/* Return backtrace of current program state. Generic version. - Copyright (C) 1998-2016 Free Software Foundation, Inc. +/* Return backtrace of current program state. + Copyright (C) 2003-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. - Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. + Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -17,74 +17,118 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ +#include <libc-lock.h> +#include <dlfcn.h> #include <execinfo.h> -#include <signal.h> -#include <frame.h> -#include <sigcontextinfo.h> -#include <ldsodefs.h> - -/* This implementation assumes a stack layout that matches the defaults - used by gcc's `__builtin_frame_address' and `__builtin_return_address' - (FP is the frame pointer register): - - +-----------------+ +-----------------+ - FP -> | previous FP --------> | previous FP ------>... - | | | | - | return address | | return address | - +-----------------+ +-----------------+ - - */ - -/* Get some notion of the current stack. Need not be exactly the top - of the stack, just something somewhere in the current frame. */ -#ifndef CURRENT_STACK_FRAME -# define CURRENT_STACK_FRAME ({ char __csf; &__csf; }) -#endif +#include <gnu/lib-names.h> +#include <stdlib.h> +#include <unwind.h> -/* By default we assume that the stack grows downward. */ -#ifndef INNER_THAN -# define INNER_THAN < -#endif +struct trace_arg +{ + void **array; + _Unwind_Word cfa; + int cnt; + int size; +}; + +#ifdef SHARED +static _Unwind_Reason_Code (*unwind_backtrace) (_Unwind_Trace_Fn, void *); +static _Unwind_Ptr (*unwind_getip) (struct _Unwind_Context *); +static _Unwind_Word (*unwind_getcfa) (struct _Unwind_Context *); +static void *libgcc_handle; + + +/* Dummy version in case libgcc_s does not contain the real code. */ +static _Unwind_Word +dummy_getcfa (struct _Unwind_Context *ctx __attribute__ ((unused))) +{ + return 0; +} -/* By default assume the `next' pointer in struct layout points to the - next struct layout. */ -#ifndef ADVANCE_STACK_FRAME -# define ADVANCE_STACK_FRAME(next) ((struct layout *) (next)) -#endif -/* By default, the frame pointer is just what we get from gcc. */ -#ifndef FIRST_FRAME_POINTER -# define FIRST_FRAME_POINTER __builtin_frame_address (0) +static void +init (void) +{ + libgcc_handle = __libc_dlopen (LIBGCC_S_SO); + + if (libgcc_handle == NULL) + return; + + unwind_backtrace = __libc_dlsym (libgcc_handle, "_Unwind_Backtrace"); + unwind_getip = __libc_dlsym (libgcc_handle, "_Unwind_GetIP"); + if (unwind_getip == NULL) + unwind_backtrace = NULL; + unwind_getcfa = (__libc_dlsym (libgcc_handle, "_Unwind_GetCFA") + ?: dummy_getcfa); +} +#else +# define unwind_backtrace _Unwind_Backtrace +# define unwind_getip _Unwind_GetIP +# define unwind_getcfa _Unwind_GetCFA #endif +static _Unwind_Reason_Code +backtrace_helper (struct _Unwind_Context *ctx, void *a) +{ + struct trace_arg *arg = a; + + /* We are first called with address in the __backtrace function. + Skip it. */ + if (arg->cnt != -1) + { + arg->array[arg->cnt] = (void *) unwind_getip (ctx); + + /* Check whether we make any progress. */ + _Unwind_Word cfa = unwind_getcfa (ctx); + + if (arg->cnt > 0 && arg->array[arg->cnt - 1] == arg->array[arg->cnt] + && cfa == arg->cfa) + return _URC_END_OF_STACK; + arg->cfa = cfa; + } + if (++arg->cnt == arg->size) + return _URC_END_OF_STACK; + return _URC_NO_REASON; +} + int __backtrace (void **array, int size) { - struct layout *current; - void *top_frame; - void *top_stack; - int cnt = 0; + struct trace_arg arg = { .array = array, .cfa = 0, .size = size, .cnt = -1 }; - top_frame = FIRST_FRAME_POINTER; - top_stack = CURRENT_STACK_FRAME; + if (size <= 0) + return 0; - /* We skip the call to this function, it makes no sense to record it. */ - current = ((struct layout *) top_frame); - while (cnt < size) - { - if ((void *) current INNER_THAN top_stack - || !((void *) current INNER_THAN __libc_stack_end)) - /* This means the address is out of range. Note that for the - toplevel we see a frame pointer with value NULL which clearly is - out of range. */ - break; +#ifdef SHARED + __libc_once_define (static, once); - array[cnt++] = current->return_address; + __libc_once (once, init); + if (unwind_backtrace == NULL) + return 0; +#endif - current = ADVANCE_STACK_FRAME (current->next); - } + unwind_backtrace (backtrace_helper, &arg); - return cnt; + /* _Unwind_Backtrace seems to put NULL address above + _start. Fix it up here. */ + if (arg.cnt > 1 && arg.array[arg.cnt - 1] == NULL) + --arg.cnt; + return arg.cnt != -1 ? arg.cnt : 0; } weak_alias (__backtrace, backtrace) libc_hidden_def (__backtrace) + + +#ifdef SHARED +/* Free all resources if necessary. */ +libc_freeres_fn (free_mem) +{ + unwind_backtrace = NULL; + if (libgcc_handle != NULL) + { + __libc_dlclose (libgcc_handle); + libgcc_handle = NULL; + } +} +#endif diff --git a/debug/backtracesyms.c b/debug/backtracesyms.c index ff587ee9a6..45873e4bbc 100644 --- a/debug/backtracesyms.c +++ b/debug/backtracesyms.c @@ -1,5 +1,5 @@ /* Return list with names for address in backtrace. - Copyright (C) 1998-2016 Free Software Foundation, Inc. + Copyright (C) 1998-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. diff --git a/debug/backtracesymsfd.c b/debug/backtracesymsfd.c index 9c58f80745..7604d68847 100644 --- a/debug/backtracesymsfd.c +++ b/debug/backtracesymsfd.c @@ -1,5 +1,5 @@ /* Write formatted list with names for addresses in backtrace to a file. - Copyright (C) 1998-2016 Free Software Foundation, Inc. + Copyright (C) 1998-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. diff --git a/debug/catchsegv.sh b/debug/catchsegv.sh index 3c788d2125..d1f60c4532 100755 --- a/debug/catchsegv.sh +++ b/debug/catchsegv.sh @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright (C) 1998-2016 Free Software Foundation, Inc. +# Copyright (C) 1998-2018 Free Software Foundation, Inc. # This file is part of the GNU C Library. # Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. @@ -40,7 +40,7 @@ EOF ;; --v | --ve | --ver | --vers | --versi | --versio | --version) echo 'catchsegv @PKGVERSION@@VERSION@' - echo 'Copyright (C) 2016 Free Software Foundation, Inc. + echo 'Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Ulrich Drepper.' diff --git a/debug/chk_fail.c b/debug/chk_fail.c index de5a833f40..65ce942c4c 100644 --- a/debug/chk_fail.c +++ b/debug/chk_fail.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2016 Free Software Foundation, Inc. +/* Copyright (C) 2004-2018 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 diff --git a/debug/confstr_chk.c b/debug/confstr_chk.c index bfe7d14487..c23163ec6b 100644 --- a/debug/confstr_chk.c +++ b/debug/confstr_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@readhat.com>, 20055. diff --git a/debug/dprintf_chk.c b/debug/dprintf_chk.c index 750b981d8b..df3867c61c 100644 --- a/debug/dprintf_chk.c +++ b/debug/dprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/execinfo.h b/debug/execinfo.h index d47c9e69f5..40a43325a4 100644 --- a/debug/execinfo.h +++ b/debug/execinfo.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1998-2016 Free Software Foundation, Inc. +/* Copyright (C) 1998-2018 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 diff --git a/debug/explicit_bzero_chk.c b/debug/explicit_bzero_chk.c new file mode 100644 index 0000000000..fb13a7f4b6 --- /dev/null +++ b/debug/explicit_bzero_chk.c @@ -0,0 +1,44 @@ +/* Generic implementation of __explicit_bzero_chk. + Copyright (C) 1991-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Torbjorn Granlund (tege@sics.se). + + 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 + <http://www.gnu.org/licenses/>. */ + +/* This is the generic definition of __explicit_bzero_chk. The + __explicit_bzero_chk symbol is used as the implementation of + explicit_bzero throughout glibc. If this file is overriden by an + architecture, both __explicit_bzero_chk and + __explicit_bzero_chk_internal have to be defined (the latter not as + an IFUNC). */ + +#include <string.h> + +void +__explicit_bzero_chk (void *dst, size_t len, size_t dstlen) +{ + /* Inline __memset_chk to avoid a PLT reference to __memset_chk. */ + if (__glibc_unlikely (dstlen < len)) + __chk_fail (); + memset (dst, '\0', len); + /* Compiler barrier. */ + asm volatile ("" ::: "memory"); +} + +/* libc-internal references use the hidden + __explicit_bzero_chk_internal symbol. This is necessary if + __explicit_bzero_chk is implemented as an IFUNC because some + targets do not support hidden references to IFUNC symbols. */ +strong_alias (__explicit_bzero_chk, __explicit_bzero_chk_internal) diff --git a/debug/fdelt_chk.c b/debug/fdelt_chk.c index 7fe243d217..258baf9c78 100644 --- a/debug/fdelt_chk.c +++ b/debug/fdelt_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2011-2016 Free Software Foundation, Inc. +/* Copyright (C) 2011-2018 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 diff --git a/debug/fgets_chk.c b/debug/fgets_chk.c index 6d396f9bea..f3548c7d61 100644 --- a/debug/fgets_chk.c +++ b/debug/fgets_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993-2016 Free Software Foundation, Inc. +/* Copyright (C) 1993-2018 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 @@ -29,9 +29,9 @@ #include <sys/param.h> char * -__fgets_chk (char *buf, size_t size, int n, _IO_FILE *fp) +__fgets_chk (char *buf, size_t size, int n, FILE *fp) { - _IO_size_t count; + size_t count; char *result; CHECK_FILE (fp, NULL); if (n <= 0) @@ -40,13 +40,12 @@ __fgets_chk (char *buf, size_t size, int n, _IO_FILE *fp) /* This is very tricky since a file descriptor may be in the non-blocking mode. The error flag doesn't mean much in this case. We return an error only when there is a new error. */ - int old_error = fp->_IO_file_flags & _IO_ERR_SEEN; - fp->_IO_file_flags &= ~_IO_ERR_SEEN; + int old_error = fp->_flags & _IO_ERR_SEEN; + fp->_flags &= ~_IO_ERR_SEEN; count = _IO_getline (fp, buf, MIN ((size_t) n - 1, size), '\n', 1); /* If we read in some bytes and errno is EAGAIN, that error will be reported for next read. */ - if (count == 0 || ((fp->_IO_file_flags & _IO_ERR_SEEN) - && errno != EAGAIN)) + if (count == 0 || ((fp->_flags & _IO_ERR_SEEN) && errno != EAGAIN)) result = NULL; else if (count >= size) __chk_fail (); @@ -55,7 +54,7 @@ __fgets_chk (char *buf, size_t size, int n, _IO_FILE *fp) buf[count] = '\0'; result = buf; } - fp->_IO_file_flags |= old_error; + fp->_flags |= old_error; _IO_release_lock (fp); return result; } diff --git a/debug/fgets_u_chk.c b/debug/fgets_u_chk.c index 99766fe354..924634c17b 100644 --- a/debug/fgets_u_chk.c +++ b/debug/fgets_u_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993-2016 Free Software Foundation, Inc. +/* Copyright (C) 1993-2018 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 @@ -29,9 +29,9 @@ #include <sys/param.h> char * -__fgets_unlocked_chk (char *buf, size_t size, int n, _IO_FILE *fp) +__fgets_unlocked_chk (char *buf, size_t size, int n, FILE *fp) { - _IO_size_t count; + size_t count; char *result; CHECK_FILE (fp, NULL); if (n <= 0) @@ -39,13 +39,12 @@ __fgets_unlocked_chk (char *buf, size_t size, int n, _IO_FILE *fp) /* This is very tricky since a file descriptor may be in the non-blocking mode. The error flag doesn't mean much in this case. We return an error only when there is a new error. */ - int old_error = fp->_IO_file_flags & _IO_ERR_SEEN; - fp->_IO_file_flags &= ~_IO_ERR_SEEN; + int old_error = fp->_flags & _IO_ERR_SEEN; + fp->_flags &= ~_IO_ERR_SEEN; count = _IO_getline (fp, buf, MIN ((size_t) n - 1, size), '\n', 1); /* If we read in some bytes and errno is EAGAIN, that error will be reported for next read. */ - if (count == 0 || ((fp->_IO_file_flags & _IO_ERR_SEEN) - && errno != EAGAIN)) + if (count == 0 || ((fp->_flags & _IO_ERR_SEEN) && errno != EAGAIN)) result = NULL; else if (count >= size) __chk_fail (); @@ -54,6 +53,6 @@ __fgets_unlocked_chk (char *buf, size_t size, int n, _IO_FILE *fp) buf[count] = '\0'; result = buf; } - fp->_IO_file_flags |= old_error; + fp->_flags |= old_error; return result; } diff --git a/debug/fgetws_chk.c b/debug/fgetws_chk.c index a3b7b82459..2380059f0f 100644 --- a/debug/fgetws_chk.c +++ b/debug/fgetws_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993-2016 Free Software Foundation, Inc. +/* Copyright (C) 1993-2018 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 @@ -20,9 +20,9 @@ #include <sys/param.h> wchar_t * -__fgetws_chk (wchar_t *buf, size_t size, int n, _IO_FILE *fp) +__fgetws_chk (wchar_t *buf, size_t size, int n, FILE *fp) { - _IO_size_t count; + size_t count; wchar_t *result; int old_error; CHECK_FILE (fp, NULL); @@ -32,8 +32,8 @@ __fgetws_chk (wchar_t *buf, size_t size, int n, _IO_FILE *fp) /* This is very tricky since a file descriptor may be in the non-blocking mode. The error flag doesn't mean much in this case. We return an error only when there is a new error. */ - old_error = fp->_IO_file_flags & _IO_ERR_SEEN; - fp->_IO_file_flags &= ~_IO_ERR_SEEN; + old_error = fp->_flags & _IO_ERR_SEEN; + fp->_flags &= ~_IO_ERR_SEEN; count = _IO_getwline (fp, buf, MIN ((size_t) n - 1, size), L'\n', 1); /* If we read in some bytes and errno is EAGAIN, that error will be reported for next read. */ @@ -46,7 +46,7 @@ __fgetws_chk (wchar_t *buf, size_t size, int n, _IO_FILE *fp) buf[count] = '\0'; result = buf; } - fp->_IO_file_flags |= old_error; + fp->_flags |= old_error; _IO_release_lock (fp); return result; } diff --git a/debug/fgetws_u_chk.c b/debug/fgetws_u_chk.c index caa568cc52..8147eb1e36 100644 --- a/debug/fgetws_u_chk.c +++ b/debug/fgetws_u_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993-2016 Free Software Foundation, Inc. +/* Copyright (C) 1993-2018 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 @@ -29,9 +29,9 @@ #include <sys/param.h> wchar_t * -__fgetws_unlocked_chk (wchar_t *buf, size_t size, int n, _IO_FILE *fp) +__fgetws_unlocked_chk (wchar_t *buf, size_t size, int n, FILE *fp) { - _IO_size_t count; + size_t count; wchar_t *result; int old_error; CHECK_FILE (fp, NULL); @@ -40,13 +40,12 @@ __fgetws_unlocked_chk (wchar_t *buf, size_t size, int n, _IO_FILE *fp) /* This is very tricky since a file descriptor may be in the non-blocking mode. The error flag doesn't mean much in this case. We return an error only when there is a new error. */ - old_error = fp->_IO_file_flags & _IO_ERR_SEEN; - fp->_IO_file_flags &= ~_IO_ERR_SEEN; + old_error = fp->_flags & _IO_ERR_SEEN; + fp->_flags &= ~_IO_ERR_SEEN; count = _IO_getwline (fp, buf, MIN ((size_t) n - 1, size), L'\n', 1); /* If we read in some bytes and errno is EAGAIN, that error will be reported for next read. */ - if (count == 0 || ((fp->_IO_file_flags & _IO_ERR_SEEN) - && errno != EAGAIN)) + if (count == 0 || ((fp->_flags & _IO_ERR_SEEN) && errno != EAGAIN)) result = NULL; else if (count >= size) __chk_fail (); @@ -55,6 +54,6 @@ __fgetws_unlocked_chk (wchar_t *buf, size_t size, int n, _IO_FILE *fp) buf[count] = '\0'; result = buf; } - fp->_IO_file_flags |= old_error; + fp->_flags |= old_error; return result; } diff --git a/debug/fortify_fail.c b/debug/fortify_fail.c index 71980779bc..ef6a39d151 100644 --- a/debug/fortify_fail.c +++ b/debug/fortify_fail.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2016 Free Software Foundation, Inc. +/* Copyright (C) 2007-2018 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 @@ -17,17 +17,32 @@ #include <stdio.h> #include <stdlib.h> +#include <stdbool.h> extern char **__libc_argv attribute_hidden; void -__attribute__ ((noreturn)) internal_function -__fortify_fail (const char *msg) +__attribute__ ((noreturn)) +__fortify_fail_abort (_Bool need_backtrace, const char *msg) { - /* The loop is added only to keep gcc happy. */ + /* The loop is added only to keep gcc happy. Don't pass down + __libc_argv[0] if we aren't doing backtrace since __libc_argv[0] + may point to the corrupted stack. */ while (1) - __libc_message (2, "*** %s ***: %s terminated\n", - msg, __libc_argv[0] ?: "<unknown>"); + __libc_message (need_backtrace ? (do_abort | do_backtrace) : do_abort, + "*** %s ***: %s terminated\n", + msg, + (need_backtrace && __libc_argv[0] != NULL + ? __libc_argv[0] : "<unknown>")); } + +void +__attribute__ ((noreturn)) +__fortify_fail (const char *msg) +{ + __fortify_fail_abort (true, msg); +} + libc_hidden_def (__fortify_fail) +libc_hidden_def (__fortify_fail_abort) diff --git a/debug/fprintf_chk.c b/debug/fprintf_chk.c index 0dd9ad6b60..cff4438afb 100644 --- a/debug/fprintf_chk.c +++ b/debug/fprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/fread_chk.c b/debug/fread_chk.c index ee88d37055..b0cb061d0d 100644 --- a/debug/fread_chk.c +++ b/debug/fread_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993-2016 Free Software Foundation, Inc. +/* Copyright (C) 1993-2018 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 diff --git a/debug/fread_u_chk.c b/debug/fread_u_chk.c index 1b2dbd4ae5..b3061f9745 100644 --- a/debug/fread_u_chk.c +++ b/debug/fread_u_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993-2016 Free Software Foundation, Inc. +/* Copyright (C) 1993-2018 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 diff --git a/debug/fwprintf_chk.c b/debug/fwprintf_chk.c index 1318492c53..aeb83077da 100644 --- a/debug/fwprintf_chk.c +++ b/debug/fwprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/getcwd_chk.c b/debug/getcwd_chk.c index 7451f1af17..7a932eb444 100644 --- a/debug/getcwd_chk.c +++ b/debug/getcwd_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/getdomainname_chk.c b/debug/getdomainname_chk.c index cc9afda052..70b60b3ddb 100644 --- a/debug/getdomainname_chk.c +++ b/debug/getdomainname_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/getgroups_chk.c b/debug/getgroups_chk.c index e5c4bac767..878c3f2569 100644 --- a/debug/getgroups_chk.c +++ b/debug/getgroups_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/gethostname_chk.c b/debug/gethostname_chk.c index 7ef34753c1..2d6856a55c 100644 --- a/debug/gethostname_chk.c +++ b/debug/gethostname_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/gets_chk.c b/debug/gets_chk.c index aebc9eb705..2b1416b295 100644 --- a/debug/gets_chk.c +++ b/debug/gets_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993-2016 Free Software Foundation, Inc. +/* Copyright (C) 1993-2018 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 @@ -30,7 +30,7 @@ char * __gets_chk (char *buf, size_t size) { - _IO_size_t count; + size_t count; int ch; char *retval; @@ -51,17 +51,17 @@ __gets_chk (char *buf, size_t size) /* This is very tricky since a file descriptor may be in the non-blocking mode. The error flag doesn't mean much in this case. We return an error only when there is a new error. */ - int old_error = _IO_stdin->_IO_file_flags & _IO_ERR_SEEN; - _IO_stdin->_IO_file_flags &= ~_IO_ERR_SEEN; + int old_error = _IO_stdin->_flags & _IO_ERR_SEEN; + _IO_stdin->_flags &= ~_IO_ERR_SEEN; buf[0] = (char) ch; count = _IO_getline (_IO_stdin, buf + 1, size - 1, '\n', 0) + 1; - if (_IO_stdin->_IO_file_flags & _IO_ERR_SEEN) + if (_IO_stdin->_flags & _IO_ERR_SEEN) { retval = NULL; goto unlock_return; } else - _IO_stdin->_IO_file_flags |= old_error; + _IO_stdin->_flags |= old_error; } if (count >= size) __chk_fail (); diff --git a/debug/getwd_chk.c b/debug/getwd_chk.c index 809b54dbd6..16630080d5 100644 --- a/debug/getwd_chk.c +++ b/debug/getwd_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/longjmp_chk.c b/debug/longjmp_chk.c index 4accb4c978..2c8611300c 100644 --- a/debug/longjmp_chk.c +++ b/debug/longjmp_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2016 Free Software Foundation, Inc. +/* Copyright (C) 2009-2018 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 @@ -15,11 +15,7 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ -#include <setjmp.h> - -// XXX Should move to include/setjmp.h -extern void ____longjmp_chk (__jmp_buf __env, int __val) - __attribute__ ((__noreturn__)); +#include <setjmpP.h> #define __longjmp ____longjmp_chk #define __libc_siglongjmp __longjmp_chk diff --git a/debug/mbsnrtowcs_chk.c b/debug/mbsnrtowcs_chk.c index 3b14f3ab9d..85b0bdea9e 100644 --- a/debug/mbsnrtowcs_chk.c +++ b/debug/mbsnrtowcs_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/mbsrtowcs_chk.c b/debug/mbsrtowcs_chk.c index b10ba195cd..b5be6245bc 100644 --- a/debug/mbsrtowcs_chk.c +++ b/debug/mbsrtowcs_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/mbstowcs_chk.c b/debug/mbstowcs_chk.c index ee75aaef3c..c9b75596dd 100644 --- a/debug/mbstowcs_chk.c +++ b/debug/mbstowcs_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/memcpy_chk.c b/debug/memcpy_chk.c index 04a1337099..b9a440890d 100644 --- a/debug/memcpy_chk.c +++ b/debug/memcpy_chk.c @@ -1,6 +1,6 @@ /* Copy memory to memory until the specified number of bytes has been copied with error checking. Overlap is NOT handled correctly. - Copyright (C) 1991-2016 Free Software Foundation, Inc. + Copyright (C) 1991-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Torbjorn Granlund (tege@sics.se). diff --git a/debug/memmove_chk.c b/debug/memmove_chk.c index 8e61c8ef6e..4e73dea3af 100644 --- a/debug/memmove_chk.c +++ b/debug/memmove_chk.c @@ -1,6 +1,6 @@ /* Copy memory to memory until the specified number of bytes has been copied with error checking. Overlap is handled correctly. - Copyright (C) 1991-2016 Free Software Foundation, Inc. + Copyright (C) 1991-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Torbjorn Granlund (tege@sics.se). diff --git a/debug/mempcpy_chk.c b/debug/mempcpy_chk.c index 0dc1ab6489..6af7bfb902 100644 --- a/debug/mempcpy_chk.c +++ b/debug/mempcpy_chk.c @@ -1,7 +1,7 @@ /* Copy memory to memory until the specified number of bytes has been copied, return pointer to following byte, with error checking. Overlap is NOT handled correctly. - Copyright (C) 1991-2016 Free Software Foundation, Inc. + Copyright (C) 1991-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Torbjorn Granlund (tege@sics.se). diff --git a/debug/memset_chk.c b/debug/memset_chk.c index ef437eff73..7ebff2b614 100644 --- a/debug/memset_chk.c +++ b/debug/memset_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/noophooks.c b/debug/noophooks.c index e9a7fbc883..b79358691b 100644 --- a/debug/noophooks.c +++ b/debug/noophooks.c @@ -1,5 +1,5 @@ /* Noop hooks for the instrumenting functions. - Copyright (C) 1999-2016 Free Software Foundation, Inc. + Copyright (C) 1999-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999. diff --git a/debug/obprintf_chk.c b/debug/obprintf_chk.c index 8469b5f675..3ac5a3cd4f 100644 --- a/debug/obprintf_chk.c +++ b/debug/obprintf_chk.c @@ -1,5 +1,5 @@ /* Print output of stream to given obstack. - Copyright (C) 1996-2016 Free Software Foundation, Inc. + Copyright (C) 1996-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. @@ -35,7 +35,7 @@ struct _IO_obstack_file struct obstack *obstack; }; -extern const struct _IO_jump_t _IO_obstack_jumps attribute_hidden; +extern const struct _IO_jump_t _IO_obstack_jumps libio_vtable attribute_hidden; int __obstack_vprintf_chk (struct obstack *obstack, int flags, const char *format, diff --git a/debug/pcprofile.c b/debug/pcprofile.c index 5112e2b74f..10cbdb6885 100644 --- a/debug/pcprofile.c +++ b/debug/pcprofile.c @@ -1,5 +1,5 @@ /* Profile PC and write result to FIFO. - Copyright (C) 1999-2016 Free Software Foundation, Inc. + Copyright (C) 1999-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999. @@ -22,7 +22,6 @@ #include <stdint.h> #include <stdlib.h> #include <unistd.h> -#include <libc-internal.h> /* Nonzero if we are actually doing something. */ static int active; diff --git a/debug/pcprofiledump.c b/debug/pcprofiledump.c index 2bee597d68..1e1af31eec 100644 --- a/debug/pcprofiledump.c +++ b/debug/pcprofiledump.c @@ -1,5 +1,5 @@ /* Dump information generated by PC profiling. - Copyright (C) 1999-2016 Free Software Foundation, Inc. + Copyright (C) 1999-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999. @@ -115,7 +115,7 @@ main (int argc, char *argv[]) error (EXIT_FAILURE, errno, _("cannot read header")); /* Check whether we have to swap the byte order. */ - int must_swap = (word & 0xfffffff0) == bswap_32 (0xdeb00000); + int must_swap = (word & 0x0fffffff) == bswap_32 (0xdeb00000); if (must_swap) word = bswap_32 (word); @@ -226,6 +226,6 @@ print_version (FILE *stream, struct argp_state *state) Copyright (C) %s Free Software Foundation, Inc.\n\ This is free software; see the source for copying conditions. There is NO\n\ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ -"), "2016"); +"), "2018"); fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper"); } diff --git a/debug/poll_chk.c b/debug/poll_chk.c index 395451b8ec..1852786db4 100644 --- a/debug/poll_chk.c +++ b/debug/poll_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2012-2016 Free Software Foundation, Inc. +/* Copyright (C) 2012-2018 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 diff --git a/debug/ppoll_chk.c b/debug/ppoll_chk.c index 7b6e6b6fb0..7121eebabb 100644 --- a/debug/ppoll_chk.c +++ b/debug/ppoll_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2012-2016 Free Software Foundation, Inc. +/* Copyright (C) 2012-2018 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 diff --git a/debug/pread64_chk.c b/debug/pread64_chk.c index 972c1354a8..cc22b51f49 100644 --- a/debug/pread64_chk.c +++ b/debug/pread64_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/pread_chk.c b/debug/pread_chk.c index 8afb9db649..a268bbe105 100644 --- a/debug/pread_chk.c +++ b/debug/pread_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/printf_chk.c b/debug/printf_chk.c index 1df2389325..426dc78386 100644 --- a/debug/printf_chk.c +++ b/debug/printf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/read_chk.c b/debug/read_chk.c index eee40d8b39..4a8c42e329 100644 --- a/debug/read_chk.c +++ b/debug/read_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/readlink_chk.c b/debug/readlink_chk.c index 2573025a25..c44d1d8c37 100644 --- a/debug/readlink_chk.c +++ b/debug/readlink_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/readlinkat_chk.c b/debug/readlinkat_chk.c index eb7448d474..7ebe48c7aa 100644 --- a/debug/readlinkat_chk.c +++ b/debug/readlinkat_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2006-2016 Free Software Foundation, Inc. +/* Copyright (C) 2006-2018 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 diff --git a/debug/readonly-area.c b/debug/readonly-area.c index 93d3e1eacd..4a52dae8a9 100644 --- a/debug/readonly-area.c +++ b/debug/readonly-area.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2016 Free Software Foundation, Inc. +/* Copyright (C) 2004-2018 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 diff --git a/debug/realpath_chk.c b/debug/realpath_chk.c index aed49ee855..09732bd24d 100644 --- a/debug/realpath_chk.c +++ b/debug/realpath_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/recv_chk.c b/debug/recv_chk.c index 6c05a246f4..6921cdc3c6 100644 --- a/debug/recv_chk.c +++ b/debug/recv_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/recvfrom_chk.c b/debug/recvfrom_chk.c index 26d418b419..7fd16b1366 100644 --- a/debug/recvfrom_chk.c +++ b/debug/recvfrom_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/segfault.c b/debug/segfault.c index 4f28b331d9..e1945b5846 100644 --- a/debug/segfault.c +++ b/debug/segfault.c @@ -1,5 +1,5 @@ /* Catch segmentation faults and print backtrace. - Copyright (C) 1998-2016 Free Software Foundation, Inc. + Copyright (C) 1998-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. @@ -156,7 +156,7 @@ install_handler (void) if (getenv ("SEGFAULT_USE_ALTSTACK") != 0) { void *stack_mem = malloc (2 * SIGSTKSZ); - struct sigaltstack ss; + stack_t ss; if (stack_mem != NULL) { diff --git a/debug/snprintf_chk.c b/debug/snprintf_chk.c index 6948c334de..cddba37109 100644 --- a/debug/snprintf_chk.c +++ b/debug/snprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/sprintf_chk.c b/debug/sprintf_chk.c index 34cb8a342f..78214563dd 100644 --- a/debug/sprintf_chk.c +++ b/debug/sprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/stack_chk_fail.c b/debug/stack_chk_fail.c index 4d0796f78c..d0b903c7e8 100644 --- a/debug/stack_chk_fail.c +++ b/debug/stack_chk_fail.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 @@ -17,6 +17,7 @@ #include <stdio.h> #include <stdlib.h> +#include <stdbool.h> extern char **__libc_argv attribute_hidden; @@ -25,5 +26,7 @@ void __attribute__ ((noreturn)) __stack_chk_fail (void) { - __fortify_fail ("stack smashing detected"); + __fortify_fail_abort (false, "stack smashing detected"); } + +strong_alias (__stack_chk_fail, __stack_chk_fail_local) diff --git a/debug/stack_chk_fail_local.c b/debug/stack_chk_fail_local.c index 8c469d3aa4..f389e8538c 100644 --- a/debug/stack_chk_fail_local.c +++ b/debug/stack_chk_fail_local.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/stpcpy_chk.c b/debug/stpcpy_chk.c index 7cc4a21516..ace08cfe48 100644 --- a/debug/stpcpy_chk.c +++ b/debug/stpcpy_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992-2016 Free Software Foundation, Inc. +/* Copyright (C) 1992-2018 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 diff --git a/debug/stpncpy_chk.c b/debug/stpncpy_chk.c index bcc14d3ed2..9e4cac4479 100644 --- a/debug/stpncpy_chk.c +++ b/debug/stpncpy_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993-2016 Free Software Foundation, Inc. +/* Copyright (C) 1993-2018 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 diff --git a/debug/strcat_chk.c b/debug/strcat_chk.c index 518bf0949f..396addc1db 100644 --- a/debug/strcat_chk.c +++ b/debug/strcat_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/strcpy_chk.c b/debug/strcpy_chk.c index 5173de8864..a8572091d9 100644 --- a/debug/strcpy_chk.c +++ b/debug/strcpy_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/strncat_chk.c b/debug/strncat_chk.c index 8132b2c923..c5283e58b3 100644 --- a/debug/strncat_chk.c +++ b/debug/strncat_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/strncpy_chk.c b/debug/strncpy_chk.c index 9452356122..bd44af9e01 100644 --- a/debug/strncpy_chk.c +++ b/debug/strncpy_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/swprintf_chk.c b/debug/swprintf_chk.c index 563bec44a1..35887e48e2 100644 --- a/debug/swprintf_chk.c +++ b/debug/swprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/test-stpcpy_chk.c b/debug/test-stpcpy_chk.c index 1f0bdad122..32c9d1e8d8 100644 --- a/debug/test-stpcpy_chk.c +++ b/debug/test-stpcpy_chk.c @@ -1,5 +1,5 @@ /* Test and measure stpcpy checking functions. - Copyright (C) 1999-2016 Free Software Foundation, Inc. + Copyright (C) 1999-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Jakub Jelinek <jakub@redhat.com>, 1999. diff --git a/debug/test-strcpy_chk.c b/debug/test-strcpy_chk.c index 4aab09aeb2..da3d903488 100644 --- a/debug/test-strcpy_chk.c +++ b/debug/test-strcpy_chk.c @@ -1,5 +1,5 @@ /* Test and measure __strcpy_chk functions. - Copyright (C) 1999-2016 Free Software Foundation, Inc. + Copyright (C) 1999-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Jakub Jelinek <jakub@redhat.com>, 1999. @@ -55,8 +55,9 @@ simple_strcpy_chk (char *dst, const char *src, size_t len) #include <signal.h> static int test_main (void); -#define TEST_FUNCTION test_main () -#include "../test-skeleton.c" +#define TEST_FUNCTION test_main +#include <support/test-driver.c> +#include <support/support.h> volatile int chk_fail_ok; jmp_buf chk_fail_buf; diff --git a/debug/tst-backtrace.h b/debug/tst-backtrace.h index 1a53048a49..beb57a7521 100644 --- a/debug/tst-backtrace.h +++ b/debug/tst-backtrace.h @@ -1,6 +1,6 @@ /* Test backtrace and backtrace_symbols: common code for examining backtraces. - Copyright (C) 2013-2016 Free Software Foundation, Inc. + Copyright (C) 2013-2018 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 @@ -33,7 +33,7 @@ volatile int x; /* Use this attribute to prevent inlining, so that all expected frames are present. */ -#define NO_INLINE __attribute__ ((noinline)) +#define NO_INLINE __attribute__ ((noinline, noclone, weak)) /* Look for a match in SYM from backtrace_symbols to NAME, a fragment of a function name. Ignore the filename before '(', but presume diff --git a/debug/tst-backtrace2.c b/debug/tst-backtrace2.c index d139c10638..3724664015 100644 --- a/debug/tst-backtrace2.c +++ b/debug/tst-backtrace2.c @@ -1,5 +1,5 @@ /* Test backtrace and backtrace_symbols. - Copyright (C) 2009-2016 Free Software Foundation, Inc. + Copyright (C) 2009-2018 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 @@ -24,10 +24,6 @@ #include "tst-backtrace.h" -static int do_test (void); -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" - /* The backtrace should include at least f1, f2, f3, and do_test. */ #define NUM_FUNCTIONS 4 @@ -75,7 +71,7 @@ fn1 (void) check do_test. */ } -NO_INLINE static int +NO_INLINE int fn2 (void) { fn1 (); @@ -91,7 +87,7 @@ fn3 (void) return x; } -NO_INLINE static int +NO_INLINE int do_test (void) { /* Test BZ #18084. */ @@ -103,3 +99,5 @@ do_test (void) fn3 (); return ret; } + +#include <support/test-driver.c> diff --git a/debug/tst-backtrace3.c b/debug/tst-backtrace3.c index 74514d7fe8..cb98b288d2 100644 --- a/debug/tst-backtrace3.c +++ b/debug/tst-backtrace3.c @@ -1,5 +1,5 @@ /* Test backtrace and backtrace_symbols for recursive calls. - Copyright (C) 2010-2016 Free Software Foundation, Inc. + Copyright (C) 2010-2018 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 @@ -24,10 +24,6 @@ #include "tst-backtrace.h" -static int do_test (void); -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" - /* The backtrace should include at least 3 * fn, and do_test. */ #define NUM_FUNCTIONS 4 @@ -75,9 +71,11 @@ fn (int c) return x; } -NO_INLINE static int +NO_INLINE int do_test (void) { fn (2); return ret; } + +#include <support/test-driver.c> diff --git a/debug/tst-backtrace4.c b/debug/tst-backtrace4.c index 965e6bdfb7..643c7c93fe 100644 --- a/debug/tst-backtrace4.c +++ b/debug/tst-backtrace4.c @@ -1,5 +1,5 @@ /* Test backtrace and backtrace_symbols for signal frames. - Copyright (C) 2011-2016 Free Software Foundation, Inc. + Copyright (C) 2011-2018 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 @@ -27,10 +27,6 @@ #include "tst-backtrace.h" -static int do_test (void); -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" - /* The backtrace should include at least handle_signal, a signal trampoline, 3 * fn, and do_test. */ #define NUM_FUNCTIONS 6 @@ -115,9 +111,11 @@ fn (int c) return 0; } -NO_INLINE static int +NO_INLINE int do_test (void) { fn (2); return ret; } + +#include <support/test-driver.c> diff --git a/debug/tst-backtrace5.c b/debug/tst-backtrace5.c index c049bcafbc..0e6fb1a024 100644 --- a/debug/tst-backtrace5.c +++ b/debug/tst-backtrace5.c @@ -1,6 +1,6 @@ /* Test backtrace and backtrace_symbols for signal frames, where a system call was interrupted by a signal. - Copyright (C) 2011-2016 Free Software Foundation, Inc. + Copyright (C) 2011-2018 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 @@ -32,10 +32,6 @@ # define SIGACTION_FLAGS 0 #endif -static int do_test (void); -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" - /* The backtrace should include at least handle_signal, a signal trampoline, read, 3 * fn, and do_test. */ #define NUM_FUNCTIONS 7 @@ -133,9 +129,11 @@ fn (int c, int flags) return 0; } -NO_INLINE static int +NO_INLINE int do_test (void) { fn (2, SIGACTION_FLAGS); return ret; } + +#include <support/test-driver.c> diff --git a/debug/tst-backtrace6.c b/debug/tst-backtrace6.c index 12214ce48b..6bd3758126 100644 --- a/debug/tst-backtrace6.c +++ b/debug/tst-backtrace6.c @@ -1,6 +1,6 @@ /* Test backtrace and backtrace_symbols for signal frames, where a system call was interrupted by a signal. - Copyright (C) 2013-2016 Free Software Foundation, Inc. + Copyright (C) 2013-2018 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 diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c index 4f968eee42..ca2b524b2f 100644 --- a/debug/tst-chk1.c +++ b/debug/tst-chk1.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2016 Free Software Foundation, Inc. +/* Copyright (C) 2004-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek <jakub@redhat.com>, 2004. @@ -16,6 +16,11 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ +/* This file tests gets. Force it to be declared. */ +#include <features.h> +#undef __GLIBC_USE_DEPRECATED_GETS +#define __GLIBC_USE_DEPRECATED_GETS 1 + #include <assert.h> #include <fcntl.h> #include <locale.h> @@ -143,6 +148,11 @@ do_test (void) if (memcmp (buf, "aabcdefghi", 10)) FAIL (); + memcpy (buf, "abcdefghij", 10); + bcopy (buf, buf + 1, 9); + if (memcmp (buf, "aabcdefghi", 10)) + FAIL (); + if (mempcpy (buf + 5, "abcde", 5) != buf + 10 || memcmp (buf, "aabcdabcde", 10)) FAIL (); @@ -151,6 +161,14 @@ do_test (void) if (memcmp (buf, "aabcdabcjj", 10)) FAIL (); + bzero (buf + 8, 2); + if (memcmp (buf, "aabcdabc\0\0", 10)) + FAIL (); + + explicit_bzero (buf + 6, 4); + if (memcmp (buf, "aabcda\0\0\0\0", 10)) + FAIL (); + strcpy (buf + 4, "EDCBA"); if (memcmp (buf, "aabcEDCBA", 10)) FAIL (); @@ -175,6 +193,11 @@ do_test (void) if (memcmp (buf, "aabcdefghi", 10)) FAIL (); + memcpy (buf, "abcdefghij", l0 + 10); + bcopy (buf, buf + 1, l0 + 9); + if (memcmp (buf, "aabcdefghi", 10)) + FAIL (); + if (mempcpy (buf + 5, "abcde", l0 + 5) != buf + 10 || memcmp (buf, "aabcdabcde", 10)) FAIL (); @@ -183,6 +206,14 @@ do_test (void) if (memcmp (buf, "aabcdabcjj", 10)) FAIL (); + bzero (buf + 8, l0 + 2); + if (memcmp (buf, "aabcdabc\0\0", 10)) + FAIL (); + + explicit_bzero (buf + 6, l0 + 4); + if (memcmp (buf, "aabcda\0\0\0\0", 10)) + FAIL (); + strcpy (buf + 4, str1 + 5); if (memcmp (buf, "aabcEDCBA", 10)) FAIL (); @@ -214,11 +245,18 @@ do_test (void) if (memcmp (buf, "aabcEcdZY", 10)) FAIL (); + /* The following tests are supposed to succeed at all fortify + levels, even though they overflow a.buf1 into a.buf2. */ memcpy (a.buf1, "abcdefghij", l0 + 10); memmove (a.buf1 + 1, a.buf1, l0 + 9); if (memcmp (a.buf1, "aabcdefghi", 10)) FAIL (); + memcpy (a.buf1, "abcdefghij", l0 + 10); + bcopy (a.buf1, a.buf1 + 1, l0 + 9); + if (memcmp (a.buf1, "aabcdefghi", 10)) + FAIL (); + if (mempcpy (a.buf1 + 5, "abcde", l0 + 5) != a.buf1 + 10 || memcmp (a.buf1, "aabcdabcde", 10)) FAIL (); @@ -227,6 +265,14 @@ do_test (void) if (memcmp (a.buf1, "aabcdabcjj", 10)) FAIL (); + bzero (a.buf1 + 8, l0 + 2); + if (memcmp (a.buf1, "aabcdabc\0\0", 10)) + FAIL (); + + explicit_bzero (a.buf1 + 6, l0 + 4); + if (memcmp (a.buf1, "aabcda\0\0\0\0", 10)) + FAIL (); + #if __USE_FORTIFY_LEVEL < 2 /* The following tests are supposed to crash with -D_FORTIFY_SOURCE=2 and sufficient GCC support, as the string operations overflow @@ -285,6 +331,14 @@ do_test (void) CHK_FAIL_END CHK_FAIL_START + bcopy (buf + 1, buf + 2, 9); + CHK_FAIL_END + + CHK_FAIL_START + bcopy (buf + 1, buf + 2, l0 + 9); + CHK_FAIL_END + + CHK_FAIL_START p = (char *) mempcpy (buf + 6, "abcde", 5); CHK_FAIL_END @@ -301,6 +355,22 @@ do_test (void) CHK_FAIL_END CHK_FAIL_START + bzero (buf + 9, 2); + CHK_FAIL_END + + CHK_FAIL_START + bzero (buf + 9, l0 + 2); + CHK_FAIL_END + + CHK_FAIL_START + explicit_bzero (buf + 9, 2); + CHK_FAIL_END + + CHK_FAIL_START + explicit_bzero (buf + 9, l0 + 2); + CHK_FAIL_END + + CHK_FAIL_START strcpy (buf + 5, str1 + 5); CHK_FAIL_END @@ -378,6 +448,14 @@ do_test (void) CHK_FAIL_END CHK_FAIL_START + bcopy (a.buf1 + 1, a.buf1 + 2, 9); + CHK_FAIL_END + + CHK_FAIL_START + bcopy (a.buf1 + 1, a.buf1 + 2, l0 + 9); + CHK_FAIL_END + + CHK_FAIL_START p = (char *) mempcpy (a.buf1 + 6, "abcde", 5); CHK_FAIL_END @@ -393,6 +471,22 @@ do_test (void) memset (a.buf1 + 9, 'j', l0 + 2); CHK_FAIL_END + CHK_FAIL_START + bzero (a.buf1 + 9, 2); + CHK_FAIL_END + + CHK_FAIL_START + bzero (a.buf1 + 9, l0 + 2); + CHK_FAIL_END + + CHK_FAIL_START + explicit_bzero (a.buf1 + 9, 2); + CHK_FAIL_END + + CHK_FAIL_START + explicit_bzero (a.buf1 + 9, l0 + 2); + CHK_FAIL_END + # if __USE_FORTIFY_LEVEL >= 2 # define O 0 # else diff --git a/debug/tst-longjmp_chk2.c b/debug/tst-longjmp_chk2.c index dae9ca01e5..23d3436d1d 100644 --- a/debug/tst-longjmp_chk2.c +++ b/debug/tst-longjmp_chk2.c @@ -6,15 +6,27 @@ #include <signal.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <sys/types.h> #include <sys/time.h> #include <sys/resource.h> +#include <unistd.h> +static int do_test (void); +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" static jmp_buf mainloop; static sigset_t mainsigset; -static int pass; +static volatile sig_atomic_t pass; +static void +write_indented (const char *str) +{ + for (int i = 0; i < pass; ++i) + write_message (" "); + write_message (str); +} static void stackoverflow_handler (int sig) @@ -23,13 +35,10 @@ stackoverflow_handler (int sig) /* Sanity check to keep test from looping forever (in case the longjmp chk code is slightly broken). */ pass++; - assert (pass < 5); sigaltstack (NULL, &altstack); - /* Using printf is not really kosher in signal handlers but we know - it will work. */ - printf ("%*sin signal handler\n", pass, ""); + write_indented ("in signal handler\n"); if (altstack.ss_flags & SS_ONSTACK) - printf ("%*son alternate stack\n", pass, ""); + write_indented ("on alternate stack\n"); siglongjmp (mainloop, pass); } @@ -112,8 +121,10 @@ do_test (void) else printf ("disabling alternate stack succeeded \n"); + /* Restore the signal handlers, in case we trigger a crash after the + tests above. */ + signal (SIGBUS, SIG_DFL); + signal (SIGSEGV, SIG_DFL); + return 0; } - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/debug/tst-longjmp_chk3.c b/debug/tst-longjmp_chk3.c index a8bc41c13f..8e9859e365 100644 --- a/debug/tst-longjmp_chk3.c +++ b/debug/tst-longjmp_chk3.c @@ -1,5 +1,5 @@ /* Make sure longjmp fortification catches bad signal stacks. - Copyright (C) 2013-2016 Free Software Foundation, Inc. + Copyright (C) 2013-2018 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 diff --git a/debug/tst-ssp-1.c b/debug/tst-ssp-1.c new file mode 100644 index 0000000000..da85ab00d0 --- /dev/null +++ b/debug/tst-ssp-1.c @@ -0,0 +1,45 @@ +/* Verify that __stack_chk_fail won't segfault. + Copyright (C) 2017-2018 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 + <http://www.gnu.org/licenses/>. */ + +/* Based on gcc.dg/ssp-1.c from GCC testsuite. */ + +#include <signal.h> + +static void +__attribute__ ((noinline, noclone)) +test (char *foo) +{ + int i; + + /* smash stack */ + for (i = 0; i <= 400; i++) + foo[i] = 42; +} + +static int +do_test (void) +{ + char foo[30]; + + test (foo); + + return 1; /* fail */ +} + +#define EXPECTED_SIGNAL SIGABRT +#include <support/test-driver.c> diff --git a/debug/ttyname_r_chk.c b/debug/ttyname_r_chk.c index d51d3490f6..8bbb3bb220 100644 --- a/debug/ttyname_r_chk.c +++ b/debug/ttyname_r_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/vasprintf_chk.c b/debug/vasprintf_chk.c index cb1f74a1e0..48b4741651 100644 --- a/debug/vasprintf_chk.c +++ b/debug/vasprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 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 @@ -37,12 +37,12 @@ __vasprintf_chk (char **result_ptr, int flags, const char *format, { /* Initial size of the buffer to be used. Will be doubled each time an overflow occurs. */ - const _IO_size_t init_string_size = 100; + const size_t init_string_size = 100; char *string; _IO_strfile sf; int ret; - _IO_size_t needed; - _IO_size_t allocated; + size_t needed; + size_t allocated; /* No need to clear the memory here (unlike for open_memstream) since we know we will never seek on the stream. */ string = (char *) malloc (init_string_size); @@ -55,8 +55,8 @@ __vasprintf_chk (char **result_ptr, int flags, const char *format, _IO_JUMPS (&sf._sbf) = &_IO_str_jumps; _IO_str_init_static_internal (&sf, string, init_string_size, string); sf._sbf._f._flags &= ~_IO_USER_BUF; - sf._s._allocate_buffer = (_IO_alloc_type) malloc; - sf._s._free_buffer = (_IO_free_type) free; + sf._s._allocate_buffer_unused = (_IO_alloc_type) malloc; + sf._s._free_buffer_unused = (_IO_free_type) free; /* For flags > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n can only come from read-only format strings. */ diff --git a/debug/vdprintf_chk.c b/debug/vdprintf_chk.c index 05d0bcd7e7..bc713b4962 100644 --- a/debug/vdprintf_chk.c +++ b/debug/vdprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 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 @@ -39,10 +39,7 @@ __vdprintf_chk (int d, int flags, const char *format, va_list arg) #endif _IO_no_init (&tmpfil.file, _IO_USER_LOCK, 0, &wd, &_IO_wfile_jumps); _IO_JUMPS (&tmpfil) = &_IO_file_jumps; - _IO_file_init (&tmpfil); -#if !_IO_UNIFIED_JUMPTABLES - tmpfil.vtable = NULL; -#endif + _IO_new_file_init_internal (&tmpfil); if (_IO_file_attach (&tmpfil.file, d) == NULL) { _IO_un_link (&tmpfil); diff --git a/debug/vfprintf_chk.c b/debug/vfprintf_chk.c index 4524f514b9..5babbf611e 100644 --- a/debug/vfprintf_chk.c +++ b/debug/vfprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/vfwprintf_chk.c b/debug/vfwprintf_chk.c index c3ac2307f3..1ffd18cbd2 100644 --- a/debug/vfwprintf_chk.c +++ b/debug/vfwprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/vprintf_chk.c b/debug/vprintf_chk.c index b4a959f94f..b3b2c53df2 100644 --- a/debug/vprintf_chk.c +++ b/debug/vprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/vsnprintf_chk.c b/debug/vsnprintf_chk.c index cc559d2b1d..d20d0fbd93 100644 --- a/debug/vsnprintf_chk.c +++ b/debug/vsnprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 @@ -20,7 +20,7 @@ #include "../libio/libioP.h" #include "../libio/strfile.h" -extern const struct _IO_jump_t _IO_strn_jumps attribute_hidden; +extern const struct _IO_jump_t _IO_strn_jumps libio_vtable attribute_hidden; /* Write formatted output into S, according to the format string FORMAT, writing no more than MAXLEN characters. */ diff --git a/debug/vsprintf_chk.c b/debug/vsprintf_chk.c index aa1587ce6f..9a443bb699 100644 --- a/debug/vsprintf_chk.c +++ b/debug/vsprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1994-2016 Free Software Foundation, Inc. +/* Copyright (C) 1994-2018 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 @@ -21,10 +21,10 @@ #include "../libio/strfile.h" -static int _IO_str_chk_overflow (_IO_FILE *fp, int c) __THROW; +static int _IO_str_chk_overflow (FILE *fp, int c) __THROW; static int -_IO_str_chk_overflow (_IO_FILE *fp, int c) +_IO_str_chk_overflow (FILE *fp, int c) { /* When we come to here this means the user supplied buffer is filled. */ @@ -32,7 +32,7 @@ _IO_str_chk_overflow (_IO_FILE *fp, int c) } -static const struct _IO_jump_t _IO_str_chk_jumps = +static const struct _IO_jump_t _IO_str_chk_jumps libio_vtable = { JUMP_INIT_DUMMY, JUMP_INIT(finish, _IO_str_finish), diff --git a/debug/vswprintf_chk.c b/debug/vswprintf_chk.c index 50bdb784b8..c6a7edcacd 100644 --- a/debug/vswprintf_chk.c +++ b/debug/vswprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 @@ -59,7 +59,7 @@ __vswprintf_chk (wchar_t *s, size_t maxlen, int flags, size_t slen, sf.f._sbf._f._flags2 |= _IO_FLAGS2_FORTIFY; _IO_wstr_init_static (&sf.f._sbf._f, s, maxlen - 1, s); - ret = _IO_vfwprintf ((_IO_FILE *) &sf.f._sbf, format, args); + ret = _IO_vfwprintf ((FILE *) &sf.f._sbf, format, args); if (sf.f._sbf._f._wide_data->_IO_buf_base == sf.overflow_buf) /* ISO C99 requires swprintf/vswprintf to return an error if the diff --git a/debug/vwprintf_chk.c b/debug/vwprintf_chk.c index c954e29915..51b67c159d 100644 --- a/debug/vwprintf_chk.c +++ b/debug/vwprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/warning-nop.c b/debug/warning-nop.c index f93221fc67..6221ded4b6 100644 --- a/debug/warning-nop.c +++ b/debug/warning-nop.c @@ -1,5 +1,5 @@ /* Dummy nop functions to elicit link-time warnings. - Copyright (C) 2005-2016 Free Software Foundation, Inc. + Copyright (C) 2005-2018 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 diff --git a/debug/wcpcpy_chk.c b/debug/wcpcpy_chk.c index 36a17f0429..41e00dc6e7 100644 --- a/debug/wcpcpy_chk.c +++ b/debug/wcpcpy_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2016 Free Software Foundation, Inc. +/* Copyright (C) 1996-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996. diff --git a/debug/wcpncpy_chk.c b/debug/wcpncpy_chk.c index e370535458..971f8c1bb9 100644 --- a/debug/wcpncpy_chk.c +++ b/debug/wcpncpy_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. diff --git a/debug/wcrtomb_chk.c b/debug/wcrtomb_chk.c index d4c5eb2239..bff1a26886 100644 --- a/debug/wcrtomb_chk.c +++ b/debug/wcrtomb_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/wcscat_chk.c b/debug/wcscat_chk.c index 9a5db3ff44..d1f3b865d0 100644 --- a/debug/wcscat_chk.c +++ b/debug/wcscat_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. diff --git a/debug/wcscpy_chk.c b/debug/wcscpy_chk.c index 9cd9dd0991..11f31e5285 100644 --- a/debug/wcscpy_chk.c +++ b/debug/wcscpy_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. diff --git a/debug/wcsncat_chk.c b/debug/wcsncat_chk.c index b5dd3d93cb..99b4d778d2 100644 --- a/debug/wcsncat_chk.c +++ b/debug/wcsncat_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. diff --git a/debug/wcsncpy_chk.c b/debug/wcsncpy_chk.c index 79f1e4504c..06b758805f 100644 --- a/debug/wcsncpy_chk.c +++ b/debug/wcsncpy_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. diff --git a/debug/wcsnrtombs_chk.c b/debug/wcsnrtombs_chk.c index 5ba6232487..11affe3aab 100644 --- a/debug/wcsnrtombs_chk.c +++ b/debug/wcsnrtombs_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/wcsrtombs_chk.c b/debug/wcsrtombs_chk.c index d7733c602e..8e72d4bf1e 100644 --- a/debug/wcsrtombs_chk.c +++ b/debug/wcsrtombs_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/wcstombs_chk.c b/debug/wcstombs_chk.c index 48b0842aa1..8bb056b3aa 100644 --- a/debug/wcstombs_chk.c +++ b/debug/wcstombs_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/wctomb_chk.c b/debug/wctomb_chk.c index 9cfa5efc8e..d8e193daf1 100644 --- a/debug/wctomb_chk.c +++ b/debug/wctomb_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2016 Free Software Foundation, Inc. +/* Copyright (C) 2005-2018 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 diff --git a/debug/wmemcpy_chk.c b/debug/wmemcpy_chk.c index ef14a201d6..9cfdcbab16 100644 --- a/debug/wmemcpy_chk.c +++ b/debug/wmemcpy_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2016 Free Software Foundation, Inc. +/* Copyright (C) 1996-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.org>, 1996. diff --git a/debug/wmemmove_chk.c b/debug/wmemmove_chk.c index 329aef546c..8875add1d7 100644 --- a/debug/wmemmove_chk.c +++ b/debug/wmemmove_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2016 Free Software Foundation, Inc. +/* Copyright (C) 1996-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu> diff --git a/debug/wmempcpy_chk.c b/debug/wmempcpy_chk.c index b5cc8e5572..d10b729256 100644 --- a/debug/wmempcpy_chk.c +++ b/debug/wmempcpy_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1999-2016 Free Software Foundation, Inc. +/* Copyright (C) 1999-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.org>, 1999. diff --git a/debug/wmemset_chk.c b/debug/wmemset_chk.c index 88079a1d31..ef8dcb3e66 100644 --- a/debug/wmemset_chk.c +++ b/debug/wmemset_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2016 Free Software Foundation, Inc. +/* Copyright (C) 1996-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.org>, 1996. diff --git a/debug/wprintf_chk.c b/debug/wprintf_chk.c index a22b0d426b..17023b6bb4 100644 --- a/debug/wprintf_chk.c +++ b/debug/wprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/debug/xtrace.sh b/debug/xtrace.sh index 2f69812d84..877ec319cb 100755 --- a/debug/xtrace.sh +++ b/debug/xtrace.sh @@ -1,5 +1,5 @@ #! @BASH@ -# Copyright (C) 1999-2016 Free Software Foundation, Inc. +# Copyright (C) 1999-2018 Free Software Foundation, Inc. # This file is part of the GNU C Library. # Contributed by Ulrich Drepper <drepper@gnu.org>, 1999. @@ -64,7 +64,7 @@ do_version() { printf $"Copyright (C) %s Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -" "2016" +" "2018" printf $"Written by %s. " "Ulrich Drepper" exit 0 |