From 0ecb606cb6cf65de1d9fc8a919bceb4be476c602 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 12 Jul 2007 18:26:36 +0000 Subject: 2.5-18.1 --- debug/Depend | 1 + debug/Makefile | 51 ++- debug/Versions | 21 ++ debug/backtrace.c | 94 +++++ debug/backtracesyms.c | 58 +++ debug/backtracesymsfd.c | 64 ++++ debug/catchsegv.sh | 4 +- debug/chk_fail.c | 10 +- debug/confstr_chk.c | 30 ++ debug/execinfo.h | 5 +- debug/fgets_chk.c | 67 ++++ debug/fgets_u_chk.c | 65 ++++ debug/fgetws_chk.c | 54 +++ debug/fgetws_u_chk.c | 61 ++++ debug/fprintf_chk.c | 5 +- debug/fwprintf_chk.c | 45 +++ debug/getcwd_chk.c | 31 ++ debug/getdomainname_chk.c | 29 ++ debug/getgroups_chk.c | 30 ++ debug/gethostname_chk.c | 29 ++ debug/getlogin_r_chk.c | 29 ++ debug/getwd_chk.c | 34 ++ debug/mbsnrtowcs_chk.c | 31 ++ debug/mbsrtowcs_chk.c | 31 ++ debug/mbstowcs_chk.c | 35 ++ debug/memcpy_chk.c | 66 ++++ debug/memmove_chk.c | 98 +++++ debug/mempcpy_chk.c | 67 ++++ debug/memset_chk.c | 92 +++++ debug/pread64_chk.c | 30 ++ debug/pread_chk.c | 30 ++ debug/printf_chk.c | 5 +- debug/ptsname_r_chk.c | 29 ++ debug/read_chk.c | 38 ++ debug/readlink_chk.c | 38 ++ debug/readlinkat_chk.c | 31 ++ debug/readonly-area.c | 34 ++ debug/realpath_chk.c | 60 +++ debug/recv_chk.c | 30 ++ debug/recvfrom_chk.c | 31 ++ debug/segfault.c | 214 +++++++++++ debug/snprintf_chk.c | 9 +- debug/sprintf_chk.c | 7 +- debug/stack_chk_fail.c | 33 ++ debug/stack_chk_fail_local.c | 30 ++ debug/stpcpy_chk.c | 45 +++ debug/stpncpy_chk.c | 85 +++++ debug/strcat_chk.c | 58 +++ debug/strcpy_chk.c | 68 ++++ debug/strncat_chk.c | 100 +++++ debug/strncpy_chk.c | 89 +++++ debug/swprintf_chk.c | 37 ++ debug/tst-chk1.c | 847 ++++++++++++++++++++++++++++++++++++++++++- debug/tst-lfschk1.c | 2 + debug/tst-lfschk2.c | 2 + debug/tst-lfschk3.c | 2 + debug/ttyname_r_chk.c | 29 ++ debug/vfprintf_chk.c | 6 +- debug/vfwprintf_chk.c | 43 +++ debug/vprintf_chk.c | 5 +- debug/vsnprintf_chk.c | 10 +- debug/vsprintf_chk.c | 10 +- debug/vswprintf_chk.c | 75 ++++ debug/vwprintf_chk.c | 43 +++ debug/warning-nop.c | 53 +++ debug/wcpcpy_chk.c | 45 +++ debug/wcpncpy_chk.c | 33 ++ debug/wcrtomb_chk.c | 35 ++ debug/wcscat_chk.c | 55 +++ debug/wcscpy_chk.c | 61 ++++ debug/wcsncat_chk.c | 96 +++++ debug/wcsncpy_chk.c | 33 ++ debug/wcsnrtombs_chk.c | 31 ++ debug/wcsrtombs_chk.c | 31 ++ debug/wcstombs_chk.c | 36 ++ debug/wctomb_chk.c | 36 ++ debug/wmemcpy_chk.c | 30 ++ debug/wmemmove_chk.c | 30 ++ debug/wmempcpy_chk.c | 31 ++ debug/wmemset_chk.c | 30 ++ debug/wprintf_chk.c | 46 +++ debug/xtrace.sh | 28 +- 82 files changed, 4122 insertions(+), 60 deletions(-) create mode 100644 debug/Depend create mode 100644 debug/backtrace.c create mode 100644 debug/backtracesyms.c create mode 100644 debug/backtracesymsfd.c create mode 100644 debug/confstr_chk.c create mode 100644 debug/fgets_chk.c create mode 100644 debug/fgets_u_chk.c create mode 100644 debug/fgetws_chk.c create mode 100644 debug/fgetws_u_chk.c create mode 100644 debug/fwprintf_chk.c create mode 100644 debug/getcwd_chk.c create mode 100644 debug/getdomainname_chk.c create mode 100644 debug/getgroups_chk.c create mode 100644 debug/gethostname_chk.c create mode 100644 debug/getlogin_r_chk.c create mode 100644 debug/getwd_chk.c create mode 100644 debug/mbsnrtowcs_chk.c create mode 100644 debug/mbsrtowcs_chk.c create mode 100644 debug/mbstowcs_chk.c create mode 100644 debug/memcpy_chk.c create mode 100644 debug/memmove_chk.c create mode 100644 debug/mempcpy_chk.c create mode 100644 debug/memset_chk.c create mode 100644 debug/pread64_chk.c create mode 100644 debug/pread_chk.c create mode 100644 debug/ptsname_r_chk.c create mode 100644 debug/read_chk.c create mode 100644 debug/readlink_chk.c create mode 100644 debug/readlinkat_chk.c create mode 100644 debug/readonly-area.c create mode 100644 debug/realpath_chk.c create mode 100644 debug/recv_chk.c create mode 100644 debug/recvfrom_chk.c create mode 100644 debug/segfault.c create mode 100644 debug/stack_chk_fail.c create mode 100644 debug/stack_chk_fail_local.c create mode 100644 debug/stpcpy_chk.c create mode 100644 debug/stpncpy_chk.c create mode 100644 debug/strcat_chk.c create mode 100644 debug/strcpy_chk.c create mode 100644 debug/strncat_chk.c create mode 100644 debug/strncpy_chk.c create mode 100644 debug/swprintf_chk.c create mode 100644 debug/tst-lfschk1.c create mode 100644 debug/tst-lfschk2.c create mode 100644 debug/tst-lfschk3.c create mode 100644 debug/ttyname_r_chk.c create mode 100644 debug/vfwprintf_chk.c create mode 100644 debug/vswprintf_chk.c create mode 100644 debug/vwprintf_chk.c create mode 100644 debug/warning-nop.c create mode 100644 debug/wcpcpy_chk.c create mode 100644 debug/wcpncpy_chk.c create mode 100644 debug/wcrtomb_chk.c create mode 100644 debug/wcscat_chk.c create mode 100644 debug/wcscpy_chk.c create mode 100644 debug/wcsncat_chk.c create mode 100644 debug/wcsncpy_chk.c create mode 100644 debug/wcsnrtombs_chk.c create mode 100644 debug/wcsrtombs_chk.c create mode 100644 debug/wcstombs_chk.c create mode 100644 debug/wctomb_chk.c create mode 100644 debug/wmemcpy_chk.c create mode 100644 debug/wmemmove_chk.c create mode 100644 debug/wmempcpy_chk.c create mode 100644 debug/wmemset_chk.c create mode 100644 debug/wprintf_chk.c (limited to 'debug') diff --git a/debug/Depend b/debug/Depend new file mode 100644 index 0000000000..f3e1156a4e --- /dev/null +++ b/debug/Depend @@ -0,0 +1 @@ +localedata diff --git a/debug/Makefile b/debug/Makefile index 6df06116b7..9d9b6ac96a 100644 --- a/debug/Makefile +++ b/debug/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1998, 1999, 2000, 2001, 2004 Free Software Foundation, Inc. +# Copyright (C) 1998-2001,2004,2005,2006 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,12 +24,27 @@ subdir := debug headers := execinfo.h distribute = sigcontextinfo.h register-dump.h frame.h -routines := backtrace backtracesyms backtracesymsfd noophooks \ +routines = backtrace backtracesyms backtracesymsfd noophooks \ memcpy_chk memmove_chk mempcpy_chk memset_chk stpcpy_chk \ - strcat_chk strcpy_chk strncat_chk strncpy_chk \ + strcat_chk strcpy_chk strncat_chk strncpy_chk stpncpy_chk \ sprintf_chk vsprintf_chk snprintf_chk vsnprintf_chk \ printf_chk fprintf_chk vprintf_chk vfprintf_chk \ - gets_chk chk_fail readonly-area + gets_chk chk_fail readonly-area fgets_chk fgets_u_chk \ + read_chk pread_chk pread64_chk recv_chk recvfrom_chk \ + readlink_chk readlinkat_chk getwd_chk getcwd_chk \ + realpath_chk ptsname_r_chk \ + wctomb_chk wcscpy_chk wmemcpy_chk wmemmove_chk wmempcpy_chk \ + wcpcpy_chk wcsncpy_chk wcscat_chk wcsncat_chk wmemset_chk \ + wcpncpy_chk \ + swprintf_chk vswprintf_chk wprintf_chk fwprintf_chk \ + vwprintf_chk vfwprintf_chk fgetws_chk fgetws_u_chk \ + confstr_chk getgroups_chk ttyname_r_chk getlogin_r_chk \ + gethostname_chk getdomainname_chk wcrtomb_chk mbsnrtowcs_chk \ + wcsnrtombs_chk mbsrtowcs_chk wcsrtombs_chk mbstowcs_chk \ + wcstombs_chk \ + stack_chk_fail \ + $(static-only-routines) +static-only-routines := warning-nop stack_chk_fail_local CFLAGS-backtrace.c = -fno-omit-frame-pointer CFLAGS-sprintf_chk.c = -D_IO_MTSAFE_IO @@ -41,9 +56,31 @@ CFLAGS-fprintf_chk.c = -D_IO_MTSAFE_IO $(exceptions) CFLAGS-vprintf_chk.c = -D_IO_MTSAFE_IO $(exceptions) CFLAGS-vfprintf_chk.c = -D_IO_MTSAFE_IO $(exceptions) CFLAGS-gets_chk.c = -D_IO_MTSAFE_IO $(exceptions) +CFLAGS-fgets_chk.c = -D_IO_MTSAFE_IO $(exceptions) +CFLAGS-fgets_u_chk.c = -D_IO_MTSAFE_IO $(exceptions) +CFLAGS-swprintf_chk.c = -D_IO_MTSAFE_IO +CFLAGS-vswprintf_chk.c = -D_IO_MTSAFE_IO +CFLAGS-wprintf_chk.c = -D_IO_MTSAFE_IO $(exceptions) +CFLAGS-fwprintf_chk.c = -D_IO_MTSAFE_IO $(exceptions) +CFLAGS-vwprintf_chk.c = -D_IO_MTSAFE_IO $(exceptions) +CFLAGS-vfwprintf_chk.c = -D_IO_MTSAFE_IO $(exceptions) +CFLAGS-fgetws_chk.c = -D_IO_MTSAFE_IO $(exceptions) +CFLAGS-fgetws_u_chk.c = -D_IO_MTSAFE_IO $(exceptions) +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 + +tst-chk1-ENV = LOCPATH=$(common-objpfx)localedata +tst-chk2-ENV = LOCPATH=$(common-objpfx)localedata +tst-chk3-ENV = LOCPATH=$(common-objpfx)localedata +tst-lfschk1-ENV = LOCPATH=$(common-objpfx)localedata +tst-lfschk2-ENV = LOCPATH=$(common-objpfx)localedata +tst-lfschk3-ENV = LOCPATH=$(common-objpfx)localedata tests = backtrace-tst tst-chk1 tst-chk2 tst-chk3 \ - test-strcpy_chk test-stpcpy_chk + tst-lfschk1 tst-lfschk2 tst-lfschk3 test-strcpy_chk test-stpcpy_chk extra-libs = libSegFault libpcprofile extra-libs-others = $(extra-libs) @@ -70,6 +107,8 @@ generated = catchsegv xtrace include ../Rules +sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,') + $(objpfx)catchsegv: catchsegv.sh $(common-objpfx)soversions.mk \ $(common-objpfx)config.make slibpfx=`echo $(slibdir)|sed 's/lib\(64\|\)$$/\\\\\\\\$$LIB/'`; \ @@ -82,7 +121,7 @@ $(objpfx)pcprofiledump: $(objpfx)pcprofiledump.o $(objpfx)xtrace: xtrace.sh rm -f $@.new sed -e 's|@BASH@|$(BASH)|' -e 's|@VERSION@|$(version)|' \ - -e 's|@SLIBDIR@|$(slibdir)|' -e 's|@BINDIR@|$(bindir)|' $^ > $@.new \ + -e 's|@SLIBDIR@|$(sLIBdir)|' -e 's|@BINDIR@|$(bindir)|' $^ > $@.new \ && rm -f $@ && mv $@.new $@ && chmod +x $@ # Depend on libc.so so a DT_NEEDED is generated in the shared objects. diff --git a/debug/Versions b/debug/Versions index 07d6fbb830..5c87af27c1 100644 --- a/debug/Versions +++ b/debug/Versions @@ -18,4 +18,25 @@ libc { __printf_chk; __fprintf_chk; __vprintf_chk; __vfprintf_chk; __gets_chk; } + GLIBC_2.4 { + __fgets_chk; __fgets_unlocked_chk; + __read_chk; __pread_chk; __pread64_chk; + __readlink_chk; __getcwd_chk; __getwd_chk; + __recv_chk; __recvfrom_chk; + __realpath_chk; __ptsname_r_chk; __wctomb_chk; + __stpncpy_chk; + __wcscpy_chk; __wmemcpy_chk; __wmemmove_chk; __wmempcpy_chk; __wcpcpy_chk; + __wcsncpy_chk; __wcscat_chk; __wcsncat_chk; __wmemset_chk; __wcpncpy_chk; + __swprintf_chk; __vswprintf_chk; __wprintf_chk; __fwprintf_chk; + __vwprintf_chk; __vfwprintf_chk; __fgetws_chk; __fgetws_unlocked_chk; + __confstr_chk; __getgroups_chk; __ttyname_r_chk; __getlogin_r_chk; + __gethostname_chk; __getdomainname_chk; __wcrtomb_chk; __mbsnrtowcs_chk; + __wcsnrtombs_chk; __mbsrtowcs_chk; __wcsrtombs_chk; __mbstowcs_chk; + __wcstombs_chk; + + __stack_chk_fail; + } + GLIBC_2.5 { + __readlinkat_chk; + } } diff --git a/debug/backtrace.c b/debug/backtrace.c new file mode 100644 index 0000000000..f2d52372d5 --- /dev/null +++ b/debug/backtrace.c @@ -0,0 +1,94 @@ +/* Return backtrace of current program state. Generic version. + Copyright (C) 1998, 2000, 2002, 2004, 2005 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1998. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include + +/* 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 + +/* By default we assume that the stack grows downward. */ +#ifndef INNER_THAN +# define INNER_THAN < +#endif + +/* By default assume the `next' pointer in struct layout points to the + next struct layout. */ +#ifndef ADVANCE_STACK_FRAME +# define ADVANCE_STACK_FRAME(next) BOUNDED_1 ((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) +#endif + +int +__backtrace (array, size) + void **array; + int size; +{ + struct layout *current; + void *__unbounded top_frame; + void *__unbounded top_stack; + int cnt = 0; + + top_frame = FIRST_FRAME_POINTER; + top_stack = CURRENT_STACK_FRAME; + + /* We skip the call to this function, it makes no sense to record it. */ + current = BOUNDED_1 ((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; + + array[cnt++] = current->return_address; + + current = ADVANCE_STACK_FRAME (current->next); + } + + return cnt; +} +weak_alias (__backtrace, backtrace) +libc_hidden_def (__backtrace) diff --git a/debug/backtracesyms.c b/debug/backtracesyms.c new file mode 100644 index 0000000000..db7ba36d0f --- /dev/null +++ b/debug/backtracesyms.c @@ -0,0 +1,58 @@ +/* Return list with names for address in backtrace. + Copyright (C) 1998, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1998. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + + +/* Assume the worst for the width of an address. */ +#define WORD_WIDTH 16 + + +char ** +__backtrace_symbols (array, size) + void *const *array; + int size; +{ + int cnt; + size_t total = 0; + char **result; + + /* We can compute the text size needed for the symbols since we print + them all as "[+0x]". */ + total = size * (WORD_WIDTH + 6); + + /* Allocate memory for the result. */ + result = malloc (size * sizeof (char *) + total); + if (result != NULL) + { + char *last = (char *) (result + size); + + for (cnt = 0; cnt < size; ++cnt) + { + result[cnt] = last; + last += 1 + sprintf (last, "[+%p]", array[cnt]); + } + } + + return result; +} +weak_alias (__backtrace_symbols, backtrace_symbols) diff --git a/debug/backtracesymsfd.c b/debug/backtracesymsfd.c new file mode 100644 index 0000000000..b01f8b0094 --- /dev/null +++ b/debug/backtracesymsfd.c @@ -0,0 +1,64 @@ +/* Write formatted list with names for addresses in backtrace to a file. + Copyright (C) 1998, 2003, 2005 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1998. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +#include +#include + +#if __ELF_NATIVE_CLASS == 32 +# define WORD_WIDTH 8 +#else +/* We assume 64bits. */ +# define WORD_WIDTH 16 +#endif + + +void +__backtrace_symbols_fd (array, size, fd) + void *const *array; + int size; + int fd; +{ + struct iovec iov[3]; + int cnt; + + for (cnt = 0; cnt < size; ++cnt) + { + char buf[WORD_WIDTH]; + + iov[0].iov_base = (void *) "[0x"; + iov[0].iov_len = 3; + + iov[1].iov_base = _itoa_word ((unsigned long int) array[cnt], + &buf[WORD_WIDTH], 16, 0); + iov[1].iov_len = &buf[WORD_WIDTH] - (char *) iov[1].iov_base; + + iov[2].iov_base = (void *) "]\n"; + iov[2].iov_len = 2; + + /* We prefer to use the non-cancelable interface if it is available. */ + writev_not_cancel_no_status (fd, iov, 3); + } +} +weak_alias (__backtrace_symbols_fd, backtrace_symbols_fd) +libc_hidden_def (__backtrace_symbols_fd) diff --git a/debug/catchsegv.sh b/debug/catchsegv.sh index 14556f712a..f4d971e34b 100755 --- a/debug/catchsegv.sh +++ b/debug/catchsegv.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 1998, 1999, 2001, 2003, 2004 Free Software Foundation, Inc. +# Copyright (C) 1998,1999,2001,2003,2004,2006 Free Software Foundation, Inc. # This file is part of the GNU C Library. # Contributed by Ulrich Drepper , 1998. @@ -39,7 +39,7 @@ if test $# -eq 0; then ;; --v | --ve | --ver | --vers | --versi | --versio | --version) echo 'catchsegv (GNU libc) @VERSION@' - echo 'Copyright (C) 2004 Free Software Foundation, Inc. + echo 'Copyright (C) 2006 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 dc1c3d70b6..0cfca295a9 100644 --- a/debug/chk_fail.c +++ b/debug/chk_fail.c @@ -1,5 +1,4 @@ - -/* Copyright (C) 2004 Free Software Foundation, Inc. +/* Copyright (C) 2004, 2005 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 +20,15 @@ #include +extern char **__libc_argv attribute_hidden; + void __attribute__ ((noreturn)) __chk_fail (void) { - __libc_fatal ("*** buffer overflow detected ***\n"); + /* The loop is added only to keep gcc happy. */ + while (1) + __libc_message (2, "*** buffer overflow detected ***: %s terminated\n", + __libc_argv[0] ?: ""); } libc_hidden_def (__chk_fail) diff --git a/debug/confstr_chk.c b/debug/confstr_chk.c new file mode 100644 index 0000000000..dae7714fcf --- /dev/null +++ b/debug/confstr_chk.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2005 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 20055. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + + +size_t +__confstr_chk (int name, char *buf, size_t len, size_t buflen) +{ + if (__builtin_expect (buflen < len, 0)) + __chk_fail (); + + return confstr (name, buf, len); +} diff --git a/debug/execinfo.h b/debug/execinfo.h index fa9927c71a..c1614cc1f0 100644 --- a/debug/execinfo.h +++ b/debug/execinfo.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc. +/* Copyright (C) 1998, 1999, 2004, 2005 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 @@ -35,8 +35,7 @@ extern char **backtrace_symbols (void *__const *__array, int __size) /* This function is similar to backtrace_symbols() but it writes the result - immediately to a file and can therefore also be used in situations where - malloc() is not usable anymore. */ + immediately to a file. */ extern void backtrace_symbols_fd (void *__const *__array, int __size, int __fd) __THROW __nonnull ((1)); diff --git a/debug/fgets_chk.c b/debug/fgets_chk.c new file mode 100644 index 0000000000..27fbede7f0 --- /dev/null +++ b/debug/fgets_chk.c @@ -0,0 +1,67 @@ +/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2002, 2003, 2005 + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. + + As a special exception, if you link the code in this file with + files compiled with a GNU compiler to produce an executable, + that does not cause the resulting executable to be covered by + the GNU Lesser General Public License. This exception does not + however invalidate any other reasons why the executable file + might be covered by the GNU Lesser General Public License. + This exception applies to code released by its copyright holders + in files containing the exception. */ + +#include "libioP.h" +#include +#include + +char * +__fgets_chk (buf, size, n, fp) + char *buf; + size_t size; + int n; + _IO_FILE *fp; +{ + _IO_size_t count; + char *result; + CHECK_FILE (fp, NULL); + if (n <= 0) + return NULL; + _IO_acquire_lock (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; + count = INTUSE(_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)) + result = NULL; + else if (count >= size) + __chk_fail (); + else + { + buf[count] = '\0'; + result = buf; + } + fp->_IO_file_flags |= old_error; + _IO_release_lock (fp); + return result; +} diff --git a/debug/fgets_u_chk.c b/debug/fgets_u_chk.c new file mode 100644 index 0000000000..324d7e371b --- /dev/null +++ b/debug/fgets_u_chk.c @@ -0,0 +1,65 @@ +/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2002, 2003, 2005 + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. + + As a special exception, if you link the code in this file with + files compiled with a GNU compiler to produce an executable, + that does not cause the resulting executable to be covered by + the GNU Lesser General Public License. This exception does not + however invalidate any other reasons why the executable file + might be covered by the GNU Lesser General Public License. + This exception applies to code released by its copyright holders + in files containing the exception. */ + +#include "libioP.h" +#include +#include + +char * +__fgets_unlocked_chk (buf, size, n, fp) + char *buf; + size_t size; + int n; + _IO_FILE *fp; +{ + _IO_size_t count; + char *result; + CHECK_FILE (fp, NULL); + if (n <= 0) + return NULL; + /* 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; + count = INTUSE(_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)) + result = NULL; + else if (count >= size) + __chk_fail (); + else + { + buf[count] = '\0'; + result = buf; + } + fp->_IO_file_flags |= old_error; + return result; +} diff --git a/debug/fgetws_chk.c b/debug/fgetws_chk.c new file mode 100644 index 0000000000..d080ccb473 --- /dev/null +++ b/debug/fgetws_chk.c @@ -0,0 +1,54 @@ +/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2001, 2005 + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include "libioP.h" +#include +#include + +wchar_t * +__fgetws_chk (wchar_t *buf, size_t size, int n, _IO_FILE *fp) +{ + _IO_size_t count; + wchar_t *result; + int old_error; + CHECK_FILE (fp, NULL); + if (n <= 0) + return NULL; + _IO_acquire_lock (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; + 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 || (_IO_ferror_unlocked (fp) && errno != EAGAIN)) + result = NULL; + else if (count >= size) + __chk_fail (); + else + { + buf[count] = '\0'; + result = buf; + } + fp->_IO_file_flags |= old_error; + _IO_release_lock (fp); + return result; +} diff --git a/debug/fgetws_u_chk.c b/debug/fgetws_u_chk.c new file mode 100644 index 0000000000..b6cc87b80d --- /dev/null +++ b/debug/fgetws_u_chk.c @@ -0,0 +1,61 @@ +/* Copyright (C) 1993, 95, 96, 97, 98, 99, 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. + + As a special exception, if you link the code in this file with + files compiled with a GNU compiler to produce an executable, + that does not cause the resulting executable to be covered by + the GNU Lesser General Public License. This exception does not + however invalidate any other reasons why the executable file + might be covered by the GNU Lesser General Public License. + This exception applies to code released by its copyright holders + in files containing the exception. */ + +#include "libioP.h" +#include +#include + +wchar_t * +__fgetws_unlocked_chk (wchar_t *buf, size_t size, int n, _IO_FILE *fp) +{ + _IO_size_t count; + wchar_t *result; + int old_error; + CHECK_FILE (fp, NULL); + if (n <= 0) + return NULL; + /* 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; + 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)) + result = NULL; + else if (count >= size) + __chk_fail (); + else + { + buf[count] = '\0'; + result = buf; + } + fp->_IO_file_flags |= old_error; + return result; +} diff --git a/debug/fprintf_chk.c b/debug/fprintf_chk.c index 2b7d22b6a6..58b5fb2b3e 100644 --- a/debug/fprintf_chk.c +++ b/debug/fprintf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1995, 1996, 1997, 2001, 2004 +/* Copyright (C) 1991, 1995, 1996, 1997, 2001, 2004, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -24,7 +24,7 @@ /* Write formatted output to FP from the format string FORMAT. */ int -__fprintf_chk (FILE *fp, int flag, const char *format, ...) +___fprintf_chk (FILE *fp, int flag, const char *format, ...) { va_list ap; int done; @@ -43,3 +43,4 @@ __fprintf_chk (FILE *fp, int flag, const char *format, ...) return done; } +ldbl_strong_alias (___fprintf_chk, __fprintf_chk) diff --git a/debug/fwprintf_chk.c b/debug/fwprintf_chk.c new file mode 100644 index 0000000000..710c89f3c8 --- /dev/null +++ b/debug/fwprintf_chk.c @@ -0,0 +1,45 @@ +/* Copyright (C) 1991, 1995, 1996, 1997, 2001, 2004, 2005 + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include "../libio/libioP.h" + + +/* Write formatted output to FP from the format string FORMAT. */ +int +__fwprintf_chk (FILE *fp, int flag, const wchar_t *format, ...) +{ + va_list ap; + int done; + + _IO_acquire_lock (fp); + if (flag > 0) + fp->_flags2 |= _IO_FLAGS2_FORTIFY; + + va_start (ap, format); + done = _IO_vfwprintf (fp, format, ap); + va_end (ap); + + if (flag > 0) + fp->_flags2 &= ~_IO_FLAGS2_FORTIFY; + _IO_release_lock (fp); + + return done; +} diff --git a/debug/getcwd_chk.c b/debug/getcwd_chk.c new file mode 100644 index 0000000000..cb864c858e --- /dev/null +++ b/debug/getcwd_chk.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + + +char * +__getcwd_chk (char *buf, size_t size, size_t buflen) +{ + if (size > buflen) + __chk_fail (); + + return __getcwd (buf, size); +} diff --git a/debug/getdomainname_chk.c b/debug/getdomainname_chk.c new file mode 100644 index 0000000000..a85464589b --- /dev/null +++ b/debug/getdomainname_chk.c @@ -0,0 +1,29 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + + +int +__getdomainname_chk (char *buf, size_t buflen, size_t nreal) +{ + if (buflen > nreal) + __chk_fail (); + + return getdomainname (buf, buflen); +} diff --git a/debug/getgroups_chk.c b/debug/getgroups_chk.c new file mode 100644 index 0000000000..c877ddb9ca --- /dev/null +++ b/debug/getgroups_chk.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + + +int +__getgroups_chk (int size, __gid_t list[], size_t listlen) +{ + if (__builtin_expect (size * sizeof (__gid_t) > listlen, 0)) + __chk_fail (); + + return __getgroups (size, list); +} diff --git a/debug/gethostname_chk.c b/debug/gethostname_chk.c new file mode 100644 index 0000000000..734cc56b0b --- /dev/null +++ b/debug/gethostname_chk.c @@ -0,0 +1,29 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + + +int +__gethostname_chk (char *buf, size_t buflen, size_t nreal) +{ + if (buflen > nreal) + __chk_fail (); + + return __gethostname (buf, buflen); +} diff --git a/debug/getlogin_r_chk.c b/debug/getlogin_r_chk.c new file mode 100644 index 0000000000..ae495cd7ab --- /dev/null +++ b/debug/getlogin_r_chk.c @@ -0,0 +1,29 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + + +int +__getlogin_r_chk (char *buf, size_t buflen, size_t nreal) +{ + if (buflen > nreal) + __chk_fail (); + + return getlogin_r (buf, buflen); +} diff --git a/debug/getwd_chk.c b/debug/getwd_chk.c new file mode 100644 index 0000000000..898af28d3f --- /dev/null +++ b/debug/getwd_chk.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + + +char * +__getwd_chk (char *buf, size_t buflen) +{ + char *res = __getcwd (buf, buflen); + if (res == NULL && errno == ERANGE) + __chk_fail (); + return res; +} + +link_warning (getwd, + "the `getwd' function is dangerous and should not be used.") diff --git a/debug/mbsnrtowcs_chk.c b/debug/mbsnrtowcs_chk.c new file mode 100644 index 0000000000..8872540ee0 --- /dev/null +++ b/debug/mbsnrtowcs_chk.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + + +size_t +__mbsnrtowcs_chk (wchar_t *dst, __const char **src, size_t nmc, size_t len, + mbstate_t *ps, size_t dstlen) +{ + if (__builtin_expect (dstlen < len, 0)) + __chk_fail (); + + return __mbsnrtowcs (dst, src, nmc, len, ps); +} diff --git a/debug/mbsrtowcs_chk.c b/debug/mbsrtowcs_chk.c new file mode 100644 index 0000000000..22d5a35580 --- /dev/null +++ b/debug/mbsrtowcs_chk.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + + +size_t +__mbsrtowcs_chk (wchar_t *dst, __const char **src, size_t len, + mbstate_t *ps, size_t dstlen) +{ + if (__builtin_expect (dstlen < len, 0)) + __chk_fail (); + + return __mbsrtowcs (dst, src, len, ps); +} diff --git a/debug/mbstowcs_chk.c b/debug/mbstowcs_chk.c new file mode 100644 index 0000000000..d1403c5d2b --- /dev/null +++ b/debug/mbstowcs_chk.c @@ -0,0 +1,35 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + + +size_t +__mbstowcs_chk (wchar_t *dst, const char *src, size_t len, size_t dstlen) +{ + if (__builtin_expect (dstlen < len, 0)) + __chk_fail (); + + mbstate_t state; + + memset (&state, '\0', sizeof state); + /* Return how many we wrote (or maybe an error). */ + return __mbsrtowcs (dst, &src, len, &state); +} diff --git a/debug/memcpy_chk.c b/debug/memcpy_chk.c new file mode 100644 index 0000000000..638cd0e4fb --- /dev/null +++ b/debug/memcpy_chk.c @@ -0,0 +1,66 @@ +/* Copy memory to memory until the specified number of bytes + has been copied with error checking. Overlap is NOT handled correctly. + Copyright (C) 1991, 1997, 2003, 2004 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +void * +__memcpy_chk (dstpp, srcpp, len, dstlen) + void *dstpp; + const void *srcpp; + size_t len; + size_t dstlen; +{ + if (__builtin_expect (dstlen < len, 0)) + __chk_fail (); + + unsigned long int dstp = (long int) dstpp; + unsigned long int srcp = (long int) srcpp; + + /* Copy from the beginning to the end. */ + + /* If there not too few bytes to copy, use word copy. */ + if (len >= OP_T_THRES) + { + /* Copy just a few bytes to make DSTP aligned. */ + len -= (-dstp) % OPSIZ; + BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ); + + /* Copy whole pages from SRCP to DSTP by virtual address manipulation, + as much as possible. */ + + PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len); + + /* Copy from SRCP to DSTP taking advantage of the known alignment of + DSTP. Number of bytes remaining is put in the third argument, + i.e. in LEN. This number may vary from machine to machine. */ + + WORD_COPY_FWD (dstp, srcp, len, len); + + /* Fall out and copy the tail. */ + } + + /* There are just a few bytes to copy. Use byte memory operations. */ + BYTE_COPY_FWD (dstp, srcp, len); + + return dstpp; +} diff --git a/debug/memmove_chk.c b/debug/memmove_chk.c new file mode 100644 index 0000000000..f3b74d23d9 --- /dev/null +++ b/debug/memmove_chk.c @@ -0,0 +1,98 @@ +/* Copy memory to memory until the specified number of bytes + has been copied with error checking. Overlap is handled correctly. + Copyright (C) 1991,1995,1996,1997,2003,2004 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +void * +__memmove_chk (dest, src, len, destlen) + void *dest; + const void *src; + size_t len; + size_t destlen; +{ + if (__builtin_expect (destlen < len, 0)) + __chk_fail (); + + unsigned long int dstp = (long int) dest; + unsigned long int srcp = (long int) src; + + /* This test makes the forward copying code be used whenever possible. + Reduces the working set. */ + if (dstp - srcp >= len) /* *Unsigned* compare! */ + { + /* Copy from the beginning to the end. */ + + /* If there not too few bytes to copy, use word copy. */ + if (len >= OP_T_THRES) + { + /* Copy just a few bytes to make DSTP aligned. */ + len -= (-dstp) % OPSIZ; + BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ); + + /* Copy whole pages from SRCP to DSTP by virtual address + manipulation, as much as possible. */ + + PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len); + + /* Copy from SRCP to DSTP taking advantage of the known + alignment of DSTP. Number of bytes remaining is put + in the third argument, i.e. in LEN. This number may + vary from machine to machine. */ + + WORD_COPY_FWD (dstp, srcp, len, len); + + /* Fall out and copy the tail. */ + } + + /* There are just a few bytes to copy. Use byte memory operations. */ + BYTE_COPY_FWD (dstp, srcp, len); + } + else + { + /* Copy from the end to the beginning. */ + srcp += len; + dstp += len; + + /* If there not too few bytes to copy, use word copy. */ + if (len >= OP_T_THRES) + { + /* Copy just a few bytes to make DSTP aligned. */ + len -= dstp % OPSIZ; + BYTE_COPY_BWD (dstp, srcp, dstp % OPSIZ); + + /* Copy from SRCP to DSTP taking advantage of the known + alignment of DSTP. Number of bytes remaining is put + in the third argument, i.e. in LEN. This number may + vary from machine to machine. */ + + WORD_COPY_BWD (dstp, srcp, len, len); + + /* Fall out and copy the tail. */ + } + + /* There are just a few bytes to copy. Use byte memory operations. */ + BYTE_COPY_BWD (dstp, srcp, len); + } + + return dest; +} diff --git a/debug/mempcpy_chk.c b/debug/mempcpy_chk.c new file mode 100644 index 0000000000..5297bbab92 --- /dev/null +++ b/debug/mempcpy_chk.c @@ -0,0 +1,67 @@ +/* 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, 1997, 1998, 2002, 2004 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +void * +__mempcpy_chk (dstpp, srcpp, len, dstlen) + void *dstpp; + const void *srcpp; + size_t len; + size_t dstlen; +{ + if (__builtin_expect (dstlen < len, 0)) + __chk_fail (); + + unsigned long int dstp = (long int) dstpp; + unsigned long int srcp = (long int) srcpp; + + /* Copy from the beginning to the end. */ + + /* If there not too few bytes to copy, use word copy. */ + if (len >= OP_T_THRES) + { + /* Copy just a few bytes to make DSTP aligned. */ + len -= (-dstp) % OPSIZ; + BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ); + + /* Copy whole pages from SRCP to DSTP by virtual address manipulation, + as much as possible. */ + + PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len); + + /* Copy from SRCP to DSTP taking advantage of the known alignment of + DSTP. Number of bytes remaining is put in the third argument, + i.e. in LEN. This number may vary from machine to machine. */ + + WORD_COPY_FWD (dstp, srcp, len, len); + + /* Fall out and copy the tail. */ + } + + /* There are just a few bytes to copy. Use byte memory operations. */ + BYTE_COPY_FWD (dstp, srcp, len); + + return (void *) dstp; +} diff --git a/debug/memset_chk.c b/debug/memset_chk.c new file mode 100644 index 0000000000..d6206ffc99 --- /dev/null +++ b/debug/memset_chk.c @@ -0,0 +1,92 @@ +/* Copyright (C) 1991, 1997, 2003, 2004, 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + +void * +__memset_chk (dstpp, c, len, dstlen) + void *dstpp; + int c; + size_t len; + size_t dstlen; +{ + if (__builtin_expect (dstlen < len, 0)) + __chk_fail (); + + long int dstp = (long int) dstpp; + + if (len >= 8) + { + size_t xlen; + op_t cccc; + + cccc = (unsigned char) c; + cccc |= cccc << 8; + cccc |= cccc << 16; + if (OPSIZ > 4) + /* Do the shift in two steps to avoid warning if long has 32 bits. */ + cccc |= (cccc << 16) << 16; + + /* There are at least some bytes to set. + No need to test for LEN == 0 in this alignment loop. */ + while (dstp % OPSIZ != 0) + { + ((byte *) dstp)[0] = c; + dstp += 1; + len -= 1; + } + + /* Write 8 `op_t' per iteration until less than 8 `op_t' remain. */ + xlen = len / (OPSIZ * 8); + while (xlen > 0) + { + ((op_t *) dstp)[0] = cccc; + ((op_t *) dstp)[1] = cccc; + ((op_t *) dstp)[2] = cccc; + ((op_t *) dstp)[3] = cccc; + ((op_t *) dstp)[4] = cccc; + ((op_t *) dstp)[5] = cccc; + ((op_t *) dstp)[6] = cccc; + ((op_t *) dstp)[7] = cccc; + dstp += 8 * OPSIZ; + xlen -= 1; + } + len %= OPSIZ * 8; + + /* Write 1 `op_t' per iteration until less than OPSIZ bytes remain. */ + xlen = len / OPSIZ; + while (xlen > 0) + { + ((op_t *) dstp)[0] = cccc; + dstp += OPSIZ; + xlen -= 1; + } + len %= OPSIZ; + } + + /* Write the last few bytes. */ + while (len > 0) + { + ((byte *) dstp)[0] = c; + dstp += 1; + len -= 1; + } + + return dstpp; +} diff --git a/debug/pread64_chk.c b/debug/pread64_chk.c new file mode 100644 index 0000000000..318579f0b5 --- /dev/null +++ b/debug/pread64_chk.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + + +ssize_t +__pread64_chk (int fd, void *buf, size_t nbytes, off64_t offset, size_t buflen) +{ + if (nbytes > buflen) + __chk_fail (); + + return __libc_pread64 (fd, buf, nbytes, offset); +} diff --git a/debug/pread_chk.c b/debug/pread_chk.c new file mode 100644 index 0000000000..de111eaf82 --- /dev/null +++ b/debug/pread_chk.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + + +ssize_t +__pread_chk (int fd, void *buf, size_t nbytes, off_t offset, size_t buflen) +{ + if (nbytes > buflen) + __chk_fail (); + + return __pread (fd, buf, nbytes, offset); +} diff --git a/debug/printf_chk.c b/debug/printf_chk.c index 86096b45c0..b8f00965dc 100644 --- a/debug/printf_chk.c +++ b/debug/printf_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1995, 1996, 1997, 2001, 2004 +/* Copyright (C) 1991, 1995, 1996, 1997, 2001, 2004, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -24,7 +24,7 @@ /* Write formatted output to stdout from the format string FORMAT. */ int -__printf_chk (int flag, const char *format, ...) +___printf_chk (int flag, const char *format, ...) { va_list ap; int done; @@ -43,3 +43,4 @@ __printf_chk (int flag, const char *format, ...) return done; } +ldbl_strong_alias (___printf_chk, __printf_chk) diff --git a/debug/ptsname_r_chk.c b/debug/ptsname_r_chk.c new file mode 100644 index 0000000000..5f03592bd1 --- /dev/null +++ b/debug/ptsname_r_chk.c @@ -0,0 +1,29 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + + +int +__ptsname_r_chk (int fd, char *buf, size_t buflen, size_t nreal) +{ + if (buflen > nreal) + __chk_fail (); + + return __ptsname_r (fd, buf, buflen); +} diff --git a/debug/read_chk.c b/debug/read_chk.c new file mode 100644 index 0000000000..da2bc945b7 --- /dev/null +++ b/debug/read_chk.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#ifdef HAVE_INLINED_SYSCALLS +# include +# include +#endif + + +ssize_t +__read_chk (int fd, void *buf, size_t nbytes, size_t buflen) +{ + if (nbytes > buflen) + __chk_fail (); + +#ifdef HAVE_INLINED_SYSCALLS + return INLINE_SYSCALL (read, 3, fd, buf, nbytes); +#else + return __read (fd, buf, nbytes); +#endif +} diff --git a/debug/readlink_chk.c b/debug/readlink_chk.c new file mode 100644 index 0000000000..ac18ee2c29 --- /dev/null +++ b/debug/readlink_chk.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2005 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#ifdef HAVE_INLINED_