diff options
author | Jakub Jelinek <jakub@redhat.com> | 2007-09-18 19:57:24 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2007-09-18 19:57:24 +0000 |
commit | 7913ba4d91b848ec4e5698c59d43198a3ef9215d (patch) | |
tree | afc73f6e0376ae6d07526c5efa9e941641ce1f6d /debug | |
parent | cedf9b89dd3b436ff7fad4c75d3f288ee4cd4ecd (diff) | |
download | glibc-7913ba4d91b848ec4e5698c59d43198a3ef9215d.tar glibc-7913ba4d91b848ec4e5698c59d43198a3ef9215d.tar.gz glibc-7913ba4d91b848ec4e5698c59d43198a3ef9215d.tar.bz2 glibc-7913ba4d91b848ec4e5698c59d43198a3ef9215d.zip |
Updated to fedora-glibc-20070918T1931cvs/fedora-glibc-2_6_90-14
Diffstat (limited to 'debug')
-rw-r--r-- | debug/Makefile | 28 | ||||
-rw-r--r-- | debug/Versions | 6 | ||||
-rw-r--r-- | debug/fortify_fail.c | 1 | ||||
-rw-r--r-- | debug/fread_chk.c | 56 | ||||
-rw-r--r-- | debug/fread_u_chk.c | 54 | ||||
-rw-r--r-- | debug/tst-chk1.c | 113 | ||||
-rw-r--r-- | debug/tst-chk4.cc | 1 | ||||
-rw-r--r-- | debug/tst-chk5.cc | 2 | ||||
-rw-r--r-- | debug/tst-chk6.cc | 2 | ||||
-rw-r--r-- | debug/tst-lfschk4.cc | 2 | ||||
-rw-r--r-- | debug/tst-lfschk5.cc | 2 | ||||
-rw-r--r-- | debug/tst-lfschk6.cc | 2 |
12 files changed, 251 insertions, 18 deletions
diff --git a/debug/Makefile b/debug/Makefile index c6cc588b90..a2c28f9737 100644 --- a/debug/Makefile +++ b/debug/Makefile @@ -32,7 +32,7 @@ routines = backtrace backtracesyms backtracesymsfd noophooks \ 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 \ + realpath_chk ptsname_r_chk fread_chk fread_u_chk \ wctomb_chk wcscpy_chk wmemcpy_chk wmemmove_chk wmempcpy_chk \ wcpcpy_chk wcsncpy_chk wcscat_chk wcsncat_chk wmemset_chk \ wcpncpy_chk \ @@ -58,6 +58,8 @@ 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-fread_chk.c = -D_IO_MTSAFE_IO $(exceptions) +CFLAGS-fread_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) @@ -77,15 +79,37 @@ CFLAGS-recvfrom_chk.c = -fexceptions -fasynchronous-unwind-tables CFLAGS-tst-chk1.c = -Wno-format CFLAGS-tst-chk2.c = -Wno-format CFLAGS-tst-chk3.c = -Wno-format +CFLAGS-tst-chk4.cc = -Wno-format +CFLAGS-tst-chk5.cc = -Wno-format +CFLAGS-tst-chk6.cc = -Wno-format +CFLAGS-tst-lfschk1.c = -Wno-format +CFLAGS-tst-lfschk2.c = -Wno-format +CFLAGS-tst-lfschk3.c = -Wno-format +CFLAGS-tst-lfschk4.cc = -Wno-format +CFLAGS-tst-lfschk5.cc = -Wno-format +CFLAGS-tst-lfschk6.cc = -Wno-format tst-chk1-ENV = LOCPATH=$(common-objpfx)localedata tst-chk2-ENV = LOCPATH=$(common-objpfx)localedata tst-chk3-ENV = LOCPATH=$(common-objpfx)localedata +tst-chk4-ENV = LOCPATH=$(common-objpfx)localedata +tst-chk5-ENV = LOCPATH=$(common-objpfx)localedata +tst-chk6-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 +tst-lfschk4-ENV = LOCPATH=$(common-objpfx)localedata +tst-lfschk5-ENV = LOCPATH=$(common-objpfx)localedata +tst-lfschk6-ENV = LOCPATH=$(common-objpfx)localedata +LDFLAGS-tst-chk4 = -lstdc++ +LDFLAGS-tst-chk5 = -lstdc++ +LDFLAGS-tst-chk6 = -lstdc++ +LDFLAGS-tst-lfschk4 = -lstdc++ +LDFLAGS-tst-lfschk5 = -lstdc++ +LDFLAGS-tst-lfschk6 = -lstdc++ tests = backtrace-tst tst-chk1 tst-chk2 tst-chk3 \ - tst-lfschk1 tst-lfschk2 tst-lfschk3 test-strcpy_chk test-stpcpy_chk + tst-lfschk1 tst-lfschk2 tst-lfschk3 test-strcpy_chk test-stpcpy_chk \ + tst-chk4 tst-chk5 tst-chk6 tst-lfschk4 tst-lfschk5 tst-lfschk6 extra-libs = libSegFault libpcprofile extra-libs-others = $(extra-libs) diff --git a/debug/Versions b/debug/Versions index 5c87af27c1..e467cc0602 100644 --- a/debug/Versions +++ b/debug/Versions @@ -39,4 +39,10 @@ libc { GLIBC_2.5 { __readlinkat_chk; } + GLIBC_2.7 { + __fread_chk; __fread_unlocked_chk; + } + GLIBC_PRIVATE { + __fortify_fail; + } } diff --git a/debug/fortify_fail.c b/debug/fortify_fail.c index 66494a678f..3b5821e934 100644 --- a/debug/fortify_fail.c +++ b/debug/fortify_fail.c @@ -32,3 +32,4 @@ __fortify_fail (msg) __libc_message (2, "*** %s ***: %s terminated\n", msg, __libc_argv[0] ?: "<unknown>"); } +libc_hidden_def (__fortify_fail) diff --git a/debug/fread_chk.c b/debug/fread_chk.c new file mode 100644 index 0000000000..2dbe05e155 --- /dev/null +++ b/debug/fread_chk.c @@ -0,0 +1,56 @@ +/* Copyright (C) 1993, 1995, 1997, 1998, 1999, 2002, 2003, 2007 + 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 <stdio.h> + +size_t +__fread_chk (void *__restrict ptr, size_t ptrlen, + size_t size, size_t n, FILE *__restrict stream) +{ + size_t bytes_requested = size * n; + if (__builtin_expect ((n | size) + >= (((size_t) 1) << (8 * sizeof (size_t) / 2)), 0)) + { + if (size != 0 && bytes_requested / size != n) + __chk_fail (); + } + + if (__builtin_expect (bytes_requested > ptrlen, 0)) + __chk_fail (); + + CHECK_FILE (stream, 0); + if (bytes_requested == 0) + return 0; + + size_t bytes_read; + _IO_acquire_lock (stream); + bytes_read = INTUSE(_IO_sgetn) (stream, (char *) ptr, bytes_requested); + _IO_release_lock (stream); + return bytes_requested == bytes_read ? n : bytes_read / size; +} diff --git a/debug/fread_u_chk.c b/debug/fread_u_chk.c new file mode 100644 index 0000000000..72a007e08b --- /dev/null +++ b/debug/fread_u_chk.c @@ -0,0 +1,54 @@ +/* Copyright (C) 1993, 1995, 1997, 1998, 1999, 2002, 2003, 2007 + 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 <stdio.h> + +size_t +__fread_unlocked_chk (void *__restrict ptr, size_t ptrlen, + size_t size, size_t n, FILE *__restrict stream) +{ + size_t bytes_requested = size * n; + if (__builtin_expect ((n | size) + >= (((size_t) 1) << (8 * sizeof (size_t) / 2)), 0)) + { + if (size != 0 && bytes_requested / size != n) + __chk_fail (); + } + + if (__builtin_expect (bytes_requested > ptrlen, 0)) + __chk_fail (); + + CHECK_FILE (stream, 0); + if (bytes_requested == 0) + return 0; + + size_t bytes_read + = INTUSE(_IO_sgetn) (stream, (char *) ptr, bytes_requested); + return bytes_requested == bytes_read ? n : bytes_read / size; +} diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c index c450744af5..881f2b5899 100644 --- a/debug/tst-chk1.c +++ b/debug/tst-chk1.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek <jakub@redhat.com>, 2004. @@ -52,7 +52,7 @@ do_prepare (void) } const char *strs = "abcdefgh\nABCDEFGHI\nabcdefghij\nABCDEFGHIJ"; - if (write (temp_fd, strs, strlen (strs)) != strlen (strs)) + if ((size_t) write (temp_fd, strs, strlen (strs)) != strlen (strs)) { puts ("could not write test strings into file"); unlink (temp_filename); @@ -105,7 +105,7 @@ int num2 = 987654; chk_fail_ok = 0; \ FAIL (); \ } -#if __USE_FORTIFY_LEVEL >= 2 +#if __USE_FORTIFY_LEVEL >= 2 && (!defined __cplusplus || defined __va_arg_pack) #define CHK_FAIL2_START CHK_FAIL_START #define CHK_FAIL2_END CHK_FAIL_END #else @@ -145,6 +145,12 @@ do_test (void) #endif ); +#if defined __USE_FORTIFY_LEVEL && !defined __extern_always_inline + printf ("Test skipped"); + if (l0 == 0) + return 0; +#endif + /* These ops can be done without runtime checking of object size. */ memcpy (buf, "abcdefghij", 10); memmove (buf + 1, buf, 9); @@ -283,7 +289,7 @@ do_test (void) CHK_FAIL_END CHK_FAIL_START - p = mempcpy (buf + 6, "abcde", l0 + 5); + p = (char *) mempcpy (buf + 6, "abcde", l0 + 5); CHK_FAIL_END CHK_FAIL_START @@ -306,6 +312,7 @@ do_test (void) stpncpy (buf + 6, "cd", l0 + 5); CHK_FAIL_END +# if !defined __cplusplus || defined __va_arg_pack CHK_FAIL_START sprintf (buf + 8, "%d", num1); CHK_FAIL_END @@ -313,6 +320,7 @@ do_test (void) CHK_FAIL_START snprintf (buf + 8, l0 + 3, "%d", num2); CHK_FAIL_END +# endif memcpy (buf, str1 + 2, l0 + 9); CHK_FAIL_START @@ -333,18 +341,18 @@ do_test (void) CHK_FAIL_END CHK_FAIL_START - p = mempcpy (a.buf1 + 6, "abcde", l0 + 5); + p = (char *) mempcpy (a.buf1 + 6, "abcde", l0 + 5); CHK_FAIL_END CHK_FAIL_START memset (a.buf1 + 9, 'j', l0 + 2); CHK_FAIL_END -#if __USE_FORTIFY_LEVEL >= 2 && __GNUC_PREREQ (4, 0) -# define O 0 -#else -# define O 1 -#endif +# if __USE_FORTIFY_LEVEL >= 2 && __GNUC_PREREQ (4, 0) +# define O 0 +# else +# define O 1 +# endif CHK_FAIL_START strcpy (a.buf1 + (O + 4), str1 + 5); @@ -358,6 +366,7 @@ do_test (void) strncpy (a.buf1 + (O + 6), "X", l0 + 4); CHK_FAIL_END +# if !defined __cplusplus || defined __va_arg_pack CHK_FAIL_START sprintf (a.buf1 + (O + 7), "%d", num1); CHK_FAIL_END @@ -365,6 +374,7 @@ do_test (void) CHK_FAIL_START snprintf (a.buf1 + (O + 7), l0 + 3, "%d", num2); CHK_FAIL_END +# endif memcpy (a.buf1, str1 + (3 - O), l0 + 8 + O); CHK_FAIL_START @@ -749,6 +759,75 @@ do_test (void) CHK_FAIL_END #endif + rewind (stdin); + + if (fread (buf, 1, sizeof (buf), stdin) != sizeof (buf) + || memcmp (buf, "abcdefgh\nA", 10)) + FAIL (); + if (fread (buf, sizeof (buf), 1, stdin) != 1 + || memcmp (buf, "BCDEFGHI\na", 10)) + FAIL (); + + rewind (stdin); + + if (fread (buf, l0 + 1, sizeof (buf), stdin) != sizeof (buf) + || memcmp (buf, "abcdefgh\nA", 10)) + FAIL (); + if (fread (buf, sizeof (buf), l0 + 1, stdin) != 1 + || memcmp (buf, "BCDEFGHI\na", 10)) + FAIL (); + +#if __USE_FORTIFY_LEVEL >= 1 + CHK_FAIL_START + if (fread (buf, 1, sizeof (buf) + 1, stdin) != sizeof (buf) + 1) + FAIL (); + CHK_FAIL_END + + CHK_FAIL_START + if (fread (buf, sizeof (buf) + 1, l0 + 1, stdin) != 1) + FAIL (); + CHK_FAIL_END +#endif + + rewind (stdin); + + if (fread_unlocked (buf, 1, sizeof (buf), stdin) != sizeof (buf) + || memcmp (buf, "abcdefgh\nA", 10)) + FAIL (); + if (fread_unlocked (buf, sizeof (buf), 1, stdin) != 1 + || memcmp (buf, "BCDEFGHI\na", 10)) + FAIL (); + + rewind (stdin); + + if (fread_unlocked (buf, 1, 4, stdin) != 4 + || memcmp (buf, "abcdFGHI\na", 10)) + FAIL (); + if (fread_unlocked (buf, 4, 1, stdin) != 1 + || memcmp (buf, "efghFGHI\na", 10)) + FAIL (); + + rewind (stdin); + + if (fread_unlocked (buf, l0 + 1, sizeof (buf), stdin) != sizeof (buf) + || memcmp (buf, "abcdefgh\nA", 10)) + FAIL (); + if (fread_unlocked (buf, sizeof (buf), l0 + 1, stdin) != 1 + || memcmp (buf, "BCDEFGHI\na", 10)) + FAIL (); + +#if __USE_FORTIFY_LEVEL >= 1 + CHK_FAIL_START + if (fread_unlocked (buf, 1, sizeof (buf) + 1, stdin) != sizeof (buf) + 1) + FAIL (); + CHK_FAIL_END + + CHK_FAIL_START + if (fread_unlocked (buf, sizeof (buf) + 1, l0 + 1, stdin) != 1) + FAIL (); + CHK_FAIL_END +#endif + lseek (fileno (stdin), 0, SEEK_SET); if (read (fileno (stdin), buf, sizeof (buf) - 1) != sizeof (buf) - 1 @@ -853,7 +932,8 @@ do_test (void) else { const char *sendstr = "abcdefgh\nABCDEFGH\n0123456789\n"; - if (send (sp[0], sendstr, strlen (sendstr), 0) != strlen (sendstr)) + if ((size_t) send (sp[0], sendstr, strlen (sendstr), 0) + != strlen (sendstr)) FAIL (); char recvbuf[12]; @@ -885,29 +965,30 @@ do_test (void) struct sockaddr_un sa_un; sl = sizeof (sa_un); - if (recvfrom (sp[1], recvbuf, sizeof recvbuf, MSG_PEEK, &sa_un, &sl) + if (recvfrom (sp[1], recvbuf, sizeof recvbuf, MSG_PEEK, + (struct sockaddr *) &sa_un, &sl) != sizeof recvbuf || memcmp (recvbuf, sendstr, sizeof recvbuf) != 0) FAIL (); sl = sizeof (sa_un); if (recvfrom (sp[1], recvbuf + 6, l0 + sizeof recvbuf - 7, MSG_PEEK, - &sa_un, &sl) != sizeof recvbuf - 7 + (struct sockaddr *) &sa_un, &sl) != sizeof recvbuf - 7 || memcmp (recvbuf + 6, sendstr, sizeof recvbuf - 7) != 0) FAIL (); #if __USE_FORTIFY_LEVEL >= 1 CHK_FAIL_START sl = sizeof (sa_un); - if (recvfrom (sp[1], recvbuf + 1, sizeof recvbuf, MSG_PEEK, &sa_un, &sl) - != sizeof recvbuf) + if (recvfrom (sp[1], recvbuf + 1, sizeof recvbuf, MSG_PEEK, + (struct sockaddr *) &sa_un, &sl) != sizeof recvbuf) FAIL (); CHK_FAIL_END CHK_FAIL_START sl = sizeof (sa_un); if (recvfrom (sp[1], recvbuf + 4, l0 + sizeof recvbuf - 3, MSG_PEEK, - &sa_un, &sl) != sizeof recvbuf - 3) + (struct sockaddr *) &sa_un, &sl) != sizeof recvbuf - 3) FAIL (); CHK_FAIL_END #endif diff --git a/debug/tst-chk4.cc b/debug/tst-chk4.cc new file mode 100644 index 0000000000..c82e6aac86 --- /dev/null +++ b/debug/tst-chk4.cc @@ -0,0 +1 @@ +#include "tst-chk1.c" diff --git a/debug/tst-chk5.cc b/debug/tst-chk5.cc new file mode 100644 index 0000000000..be37ce2d22 --- /dev/null +++ b/debug/tst-chk5.cc @@ -0,0 +1,2 @@ +#define _FORTIFY_SOURCE 1 +#include "tst-chk1.c" diff --git a/debug/tst-chk6.cc b/debug/tst-chk6.cc new file mode 100644 index 0000000000..38b8e4fb36 --- /dev/null +++ b/debug/tst-chk6.cc @@ -0,0 +1,2 @@ +#define _FORTIFY_SOURCE 2 +#include "tst-chk1.c" diff --git a/debug/tst-lfschk4.cc b/debug/tst-lfschk4.cc new file mode 100644 index 0000000000..f3e6d47d5e --- /dev/null +++ b/debug/tst-lfschk4.cc @@ -0,0 +1,2 @@ +#define _FILE_OFFSET_BITS 64 +#include "tst-chk1.c" diff --git a/debug/tst-lfschk5.cc b/debug/tst-lfschk5.cc new file mode 100644 index 0000000000..95d4db1d32 --- /dev/null +++ b/debug/tst-lfschk5.cc @@ -0,0 +1,2 @@ +#define _FILE_OFFSET_BITS 64 +#include "tst-chk2.c" diff --git a/debug/tst-lfschk6.cc b/debug/tst-lfschk6.cc new file mode 100644 index 0000000000..50a1ae1258 --- /dev/null +++ b/debug/tst-lfschk6.cc @@ -0,0 +1,2 @@ +#define _FILE_OFFSET_BITS 64 +#include "tst-chk3.c" |