aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-02-21 23:14:10 +0000
committerUlrich Drepper <drepper@redhat.com>2005-02-21 23:14:10 +0000
commit553cc5f9ad5408fc7fb49a33417acc1446f0c548 (patch)
treed4feec607359c614b579876e8035ce539dfac3b8
parent53360aa17295db38e5d5e0ed16548f5f002f0fa2 (diff)
downloadglibc-553cc5f9ad5408fc7fb49a33417acc1446f0c548.tar.xz
glibc-553cc5f9ad5408fc7fb49a33417acc1446f0c548.zip
* sysdeps/unix/sysv/linux/libc_fatal.c: Print backtrace and memory
map if requested. * debug/chk_fail.c: Request backtrace and memory map dump. * Versions.def: Add GLIBC_2.4 for libc. * debug/fgets_chk.c: New file. * debug/fgets_u_chk.c: New file. * debug/getcwd_chk.c: New file. * debug/getwd_chk.c: New file. * debug/readlink_chk.c: New file. * debug/read_chk.c: New file. * debug/pread_chk.c: New file. * debug/pread64_chk.c: New file. * debug/recv_chk.c: New file. * debug/recvfrom_chk.c: New file. * debug/Versions: Add all new functions with version GLIBC_2.4. * debug/Makefile (routines): Add fgets_chk, fgets_u_chk, read_chk, pread_chk, pread64_chk, recv_chk, recvfrom_chk, readlink_chk, getwd_chk, and getcwd_chk. Plus appropriate CFLAGS definitions. * debug/tst-chk1.c: Add more tests. * libio/bits/stdio2.h: Add macros for fgets and fgets_unlocked. * include/stdio.h: Declare __fgets_chk and __fgets_unlocked_chk. * posix/unistd.h: Include <bits/unistd.h> for fortification. * posix/bits/unistd.h: New file. * posix/Makefile (headers): Add bits/unistd.h. * socket/sys/socket.h: Include <bits/socket2.h> for fortification. * socket/bits/socket2.h: New file. * socket/Makefile (headers): Add bits/socket2.h. * string/bits/string3.h: Extend memset macro to check for zero 3rd parameter and use __memset_zero_constant_len_parameter in that case. * sysdeps/generic/memset_chk.c: Add __memset_zero_constant_len_parameter alias and linker warning. * debug/Versions: Add __memset_zero_constant_len_parameter to libc with version GLIBC_2.4. * sysdeps/generic/bits/types.h: Don't unnecessarily use __extension__ in __STD_TYPE definition. 2005-02-21 Jakub Jelinek <jakub@redhat.com> * malloc/malloc.c (malloc_printerr): If MALLOC_CHECK_={5,7}, print the error message rather than program name. 2005-02-21 Ulrich Drepper <drepper@redhat.com>
-rw-r--r--ChangeLog46
-rw-r--r--Versions.def1
-rw-r--r--bits/types.h11
-rw-r--r--debug/Makefile13
-rw-r--r--debug/Versions7
-rw-r--r--debug/chk_fail.c2
-rw-r--r--debug/fgets_chk.c67
-rw-r--r--debug/fgets_u_chk.c65
-rw-r--r--debug/getcwd_chk.c31
-rw-r--r--debug/getwd_chk.c34
-rw-r--r--debug/pread64_chk.c33
-rw-r--r--debug/pread_chk.c33
-rw-r--r--debug/read_chk.c41
-rw-r--r--debug/readlink_chk.c41
-rw-r--r--debug/recv_chk.c33
-rw-r--r--debug/recvfrom_chk.c35
-rw-r--r--debug/tst-chk1.c81
-rw-r--r--include/stdio.h2
-rw-r--r--libio/bits/stdio2.h19
-rw-r--r--malloc/malloc.c7
-rw-r--r--posix/Makefile2
-rw-r--r--posix/bits/unistd.h78
-rw-r--r--posix/unistd.h1
-rw-r--r--socket/Makefile4
-rw-r--r--socket/bits/socket2.h38
-rw-r--r--socket/sys/socket.h8
-rw-r--r--string/bits/string3.h17
-rw-r--r--sysdeps/generic/bits/types.h11
-rw-r--r--sysdeps/generic/memset_chk.c6
-rw-r--r--sysdeps/i386/i686/memset.S8
-rw-r--r--sysdeps/i386/i686/memset_chk.S8
-rw-r--r--sysdeps/unix/sysv/linux/libc_fatal.c30
-rw-r--r--sysdeps/x86_64/memset.S8
-rw-r--r--sysdeps/x86_64/memset_chk.S6
34 files changed, 789 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index 587fa4995d..c828841de5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,51 @@
2005-02-21 Ulrich Drepper <drepper@redhat.com>
+ * sysdeps/unix/sysv/linux/libc_fatal.c: Print backtrace and memory
+ map if requested.
+ * debug/chk_fail.c: Request backtrace and memory map dump.
+
+ * Versions.def: Add GLIBC_2.4 for libc.
+ * debug/fgets_chk.c: New file.
+ * debug/fgets_u_chk.c: New file.
+ * debug/getcwd_chk.c: New file.
+ * debug/getwd_chk.c: New file.
+ * debug/readlink_chk.c: New file.
+ * debug/read_chk.c: New file.
+ * debug/pread_chk.c: New file.
+ * debug/pread64_chk.c: New file.
+ * debug/recv_chk.c: New file.
+ * debug/recvfrom_chk.c: New file.
+ * debug/Versions: Add all new functions with version GLIBC_2.4.
+ * debug/Makefile (routines): Add fgets_chk, fgets_u_chk, read_chk,
+ pread_chk, pread64_chk, recv_chk, recvfrom_chk, readlink_chk,
+ getwd_chk, and getcwd_chk. Plus appropriate CFLAGS definitions.
+ * debug/tst-chk1.c: Add more tests.
+ * libio/bits/stdio2.h: Add macros for fgets and fgets_unlocked.
+ * include/stdio.h: Declare __fgets_chk and __fgets_unlocked_chk.
+ * posix/unistd.h: Include <bits/unistd.h> for fortification.
+ * posix/bits/unistd.h: New file.
+ * posix/Makefile (headers): Add bits/unistd.h.
+ * socket/sys/socket.h: Include <bits/socket2.h> for fortification.
+ * socket/bits/socket2.h: New file.
+ * socket/Makefile (headers): Add bits/socket2.h.
+
+ * string/bits/string3.h: Extend memset macro to check for zero 3rd
+ parameter and use __memset_zero_constant_len_parameter in that case.
+ * sysdeps/generic/memset_chk.c: Add
+ __memset_zero_constant_len_parameter alias and linker warning.
+ * debug/Versions: Add __memset_zero_constant_len_parameter to libc
+ with version GLIBC_2.4.
+
+ * sysdeps/generic/bits/types.h: Don't unnecessarily use __extension__
+ in __STD_TYPE definition.
+
+2005-02-21 Jakub Jelinek <jakub@redhat.com>
+
+ * malloc/malloc.c (malloc_printerr): If MALLOC_CHECK_={5,7}, print
+ the error message rather than program name.
+
+2005-02-21 Ulrich Drepper <drepper@redhat.com>
+
* posix/unistd.h: symlink and readlink are unconditionally
available in the 2001 spec.
diff --git a/Versions.def b/Versions.def
index 33409f1143..45b2127914 100644
--- a/Versions.def
+++ b/Versions.def
@@ -20,6 +20,7 @@ libc {
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
+ GLIBC_2.4
%ifdef USE_IN_LIBIO
HURD_CTHREADS_0.3
%endif
diff --git a/bits/types.h b/bits/types.h
index ce48964f14..65c8a9fe90 100644
--- a/bits/types.h
+++ b/bits/types.h
@@ -1,5 +1,5 @@
/* bits/types.h -- definitions of __*_t types underlying *_t types.
- Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 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
@@ -114,6 +114,9 @@ typedef struct
# define __ULONG32_TYPE unsigned long int
# define __S64_TYPE __quad_t
# define __U64_TYPE __u_quad_t
+/* We want __extension__ before typedef's that use nonstandard base types
+ such as `long long' in C89 mode. */
+# define __STD_TYPE __extension__ typedef
#elif __WORDSIZE == 64
# define __SQUAD_TYPE long int
# define __UQUAD_TYPE unsigned long int
@@ -123,15 +126,13 @@ typedef struct
# define __ULONG32_TYPE unsigned int
# define __S64_TYPE long int
# define __U64_TYPE unsigned long int
+/* No need to mark the typedef with __extension__. */
+# define __STD_TYPE typedef
#else
# error
#endif
#include <bits/typesizes.h> /* Defines __*_T_TYPE macros. */
-/* We want __extension__ before typedef's that use nonstandard base types
- such as `long long' in C89 mode. */
-#define __STD_TYPE __extension__ typedef
-
__STD_TYPE __DEV_T_TYPE __dev_t; /* Type of device numbers. */
__STD_TYPE __UID_T_TYPE __uid_t; /* Type of user identifications. */
diff --git a/debug/Makefile b/debug/Makefile
index 6df06116b7..a3f20fd9a7 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,1999,2000,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
@@ -29,7 +29,9 @@ routines := backtrace backtracesyms backtracesymsfd noophooks \
strcat_chk strcpy_chk strncat_chk strncpy_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 getwd_chk getcwd_chk
CFLAGS-backtrace.c = -fno-omit-frame-pointer
CFLAGS-sprintf_chk.c = -D_IO_MTSAFE_IO
@@ -41,6 +43,13 @@ 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-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
tests = backtrace-tst tst-chk1 tst-chk2 tst-chk3 \
test-strcpy_chk test-stpcpy_chk
diff --git a/debug/Versions b/debug/Versions
index 07d6fbb830..a4229d7852 100644
--- a/debug/Versions
+++ b/debug/Versions
@@ -18,4 +18,11 @@ 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;
+ __memset_zero_constant_len_parameter;
+ __recv_chk; __recvfrom_chk;
+ }
}
diff --git a/debug/chk_fail.c b/debug/chk_fail.c
index 6921ca4686..0cfca295a9 100644
--- a/debug/chk_fail.c
+++ b/debug/chk_fail.c
@@ -28,7 +28,7 @@ __chk_fail (void)
{
/* The loop is added only to keep gcc happy. */
while (1)
- __libc_message (1, "*** buffer overflow detected ***: %s terminated\n",
+ __libc_message (2, "*** buffer overflow detected ***: %s terminated\n",
__libc_argv[0] ?: "<unknown>");
}
libc_hidden_def (__chk_fail)
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 <stdio.h>
+#include <sys/param.h>
+
+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 <stdio.h>
+#include <sys/param.h>
+
+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/getcwd_chk.c b/debug/getcwd_chk.c
new file mode 100644
index 0000000000..9e14a0102e
--- /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 <errno.h>
+#include <unistd.h>
+#include <sys/param.h>
+
+
+char *
+__getcwd_chk (char *buf, size_t size, size_t buflen)
+{
+ char *res = __getcwd (buf, MIN (size, buflen));
+ if (res == NULL && errno == ERANGE && size > buflen)
+ __chk_fail ();
+ return res;
+}
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 <errno.h>
+#include <unistd.h>
+#include <sys/param.h>
+
+
+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/pread64_chk.c b/debug/pread64_chk.c
new file mode 100644
index 0000000000..5402e05b86
--- /dev/null
+++ b/debug/pread64_chk.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2005 Free Software