summary refs log tree commit diff
path: root/debug
diff options
context:
space:
mode:
Diffstat (limited to 'debug')
-rw-r--r--debug/Makefile17
-rw-r--r--debug/Versions6
-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.c30
-rw-r--r--debug/pread_chk.c30
-rw-r--r--debug/read_chk.c38
-rw-r--r--debug/readlink_chk.c38
-rw-r--r--debug/recv_chk.c33
-rw-r--r--debug/recvfrom_chk.c35
-rw-r--r--debug/tst-chk1.c81
-rw-r--r--debug/warning-nop.c40
15 files changed, 542 insertions, 5 deletions
diff --git a/debug/Makefile b/debug/Makefile
index 6df06116b7..c904913c35 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
@@ -24,12 +24,16 @@ 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 \
 	    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 \
+	    $(static-only-routines)
+static-only-routines := warning-nop
 
 CFLAGS-backtrace.c = -fno-omit-frame-pointer
 CFLAGS-sprintf_chk.c = -D_IO_MTSAFE_IO
@@ -41,6 +45,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..fd97834171 100644
--- a/debug/Versions
+++ b/debug/Versions
@@ -18,4 +18,10 @@ 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;
+  }
 }
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..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 <errno.h>
+#include <unistd.h>
+#include <sys/param.h>
+
+
+char *
+__getcwd_chk (char *buf, size_t size, size_t buflen)
+{
+  if (size > buflen)
+    __chk_fail ();
+
+  return __getcwd (buf, size);
+}
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..93e5151ddc
--- /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 <unistd.h>
+#include <sys/param.h>
+
+
+ssize_t
+__pread64_chk (int fd, void *buf, size_t nbytes, off64_t offset, size_t buflen)
+{
+  if (nbytes > buflen)
+    __chk_fail ();
+
+  return __pread64 (fd, buf, offset, nbytes);
+}
diff --git a/debug/pread_chk.c b/debug/pread_chk.c
new file mode 100644
index 0000000000..24c13103dd
--- /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 <unistd.h>
+#include <sys/param.h>
+
+
+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, offset, nbytes);
+}
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 <unistd.h>
+#include <sys/param.h>
+#ifdef HAVE_INLINED_SYSCALLS
+# include <errno.h>
+# include <sysdep.h>
+#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 <unistd.h>
+#include <sys/param.h>
+#ifdef HAVE_INLINED_SYSCALLS
+# include <errno.h>
+# include <sysdep.h>
+#endif
+
+
+ssize_t
+__readlink_chk (const char *path, void *buf, size_t len, size_t buflen)
+{
+  if (len > buflen)
+    __chk_fail ();
+
+#ifdef HAVE_INLINED_SYSCALLS
+  return INLINE_SYSCALL (readlink, 3, path, buf, len);
+#else
+  return __readlink (path, buf, len);
+#endif
+}
diff --git a/debug/recv_chk.c b/debug/recv_chk.c
new file mode 100644
index 0000000000..7a49d17234
--- /dev/null
+++ b/debug/recv_chk.c
@@ -0,0 +1,33 @@
+/* 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 <sys/param.h>
+#include <sys/socket.h>
+
+
+ssize_t
+__recv_chk (int fd, void *buf, size_t n, size_t buflen, int flags)
+{
+  /* In case N is greater than BUFLEN, we read BUFLEN+1 bytes.
+     This might overflow the buffer but the damage is reduced to just
+     one byte.  And the program will terminate right away.  */
+  ssize_t nrecv = __recv (fd, buf, MIN (n, buflen + 1), flags);
+  if (nrecv > 0 && (size_t) nrecv > buflen)
+    __chk_fail ();
+  return nrecv;
+}
diff --git a/debug/recvfrom_chk.c b/debug/recvfrom_chk.c
new file mode 100644
index 0000000000..e1b1da7f6b
--- /dev/null
+++ b/debug/recvfrom_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 <sys/param.h>
+#include <sys/socket.h>
+
+
+ssize_t
+__recvfrom_chk (int fd, void *buf, size_t n, size_t buflen, int flags,
+		__SOCKADDR_ARG addr, socklen_t *addr_len)
+{
+  /* In case N is greater than BUFLEN, we read BUFLEN+1 bytes.
+     This might overflow the buffer but the damage is reduced to just
+     one byte.  And the program will terminate right away.  */
+  ssize_t nrecv = __recvfrom (fd, buf, MIN (n, buflen + 1), flags,
+			      addr, addr_len);
+  if (nrecv > 0 && (size_t) nrecv > buflen)
+    __chk_fail ();
+  return nrecv;
+}
diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c
index b4607bc9f0..ea059e6f85 100644
--- a/debug/tst-chk1.c
+++ b/debug/tst-chk1.c
@@ -1,4 +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.
    Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
 
@@ -455,6 +455,85 @@ do_test (void)
   CHK_FAIL_END
 #endif
 
+  rewind (stdin);
+
+  if (fgets (buf, sizeof (buf), stdin) != buf
+      || memcmp (buf, "abcdefgh\n", 10))
+    FAIL ();
+  if (fgets (buf, sizeof (buf), stdin) != buf || memcmp (buf, "ABCDEFGHI", 10))
+    FAIL ();
+
+#if __USE_FORTIFY_LEVEL >= 1
+  CHK_FAIL_START
+  if (fgets (buf, sizeof (buf) + 1, stdin) != buf)
+    FAIL ();
+  CHK_FAIL_END
+#endif
+
+  rewind (stdin);
+
+  if (fgets_unlocked (buf, sizeof (buf), stdin) != buf
+      || memcmp (buf, "abcdefgh\n", 10))
+    FAIL ();
+  if (fgets_unlocked (buf, sizeof (buf), stdin) != buf
+      || memcmp (buf, "ABCDEFGHI", 10))
+    FAIL ();
+
+#if __USE_FORTIFY_LEVEL >= 1
+  CHK_FAIL_START
+  if (fgets_unlocked (buf, sizeof (buf) + 1, stdin) != buf)
+    FAIL ();
+  CHK_FAIL_END
+#endif
+
+  lseek (fileno (stdin), 0, SEEK_SET);
+
+  if (read (fileno (stdin), buf, sizeof (buf) - 1) != sizeof (buf) - 1
+      || memcmp (buf, "abcdefgh\n", 9))
+    FAIL ();
+  if (read (fileno (stdin), buf, sizeof (buf) - 1) != sizeof (buf) - 1
+      || memcmp (buf, "ABCDEFGHI", 9))
+    FAIL ();
+
+#if __USE_FORTIFY_LEVEL >= 1
+  CHK_FAIL_START
+  if (read (fileno (stdin), buf, sizeof (buf) + 1) != sizeof (buf) + 1)
+    FAIL ();
+  CHK_FAIL_END
+#endif
+
+  if (pread (fileno (stdin), buf, sizeof (buf) - 1, 0) != sizeof (buf) - 1
+      || memcmp (buf, "abcdefgh\n", 9))
+    FAIL ();
+  if (pread (fileno (stdin), buf, sizeof (buf) - 1, sizeof (buf) - 1)
+      != sizeof (buf) - 1
+      || memcmp (buf, "ABCDEFGHI", 9))
+    FAIL ();
+
+#if __USE_FORTIFY_LEVEL >= 1
+  CHK_FAIL_START
+  if (pread (fileno (stdin), buf, sizeof (buf) + 1, 2 * sizeof (buf))
+      != sizeof (buf) + 1)
+    FAIL ();
+  CHK_FAIL_END
+#endif
+
+  if (pread64 (fileno (stdin), buf, sizeof (buf) - 1, 0) != sizeof (buf) - 1
+      || memcmp (buf, "abcdefgh\n", 9))
+    FAIL ();
+  if (pread64 (fileno (stdin), buf, sizeof (buf) - 1, sizeof (buf) - 1)
+      != sizeof (buf) - 1
+      || memcmp (buf, "ABCDEFGHI", 9))
+    FAIL ();
+
+#if __USE_FORTIFY_LEVEL >= 1
+  CHK_FAIL_START
+  if (pread64 (fileno (stdin), buf, sizeof (buf) + 1, 2 * (sizeof (buf) - 1))
+      != sizeof (buf) + 1)
+    FAIL ();
+  CHK_FAIL_END
+#endif
+
   if (freopen (temp_filename, "r", stdin) == NULL)
     {
       puts ("could not open temporary file");
diff --git a/debug/warning-nop.c b/debug/warning-nop.c
new file mode 100644
index 0000000000..b4ebbac4dd
--- /dev/null
+++ b/debug/warning-nop.c
@@ -0,0 +1,40 @@
+/* Dummy nop functions to elicit link-time warnings.
+   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 <sys/cdefs.h>
+
+static void
+nop (void)
+{
+}
+
+/* Don't insert any other #include's before this #undef!  */
+
+#undef __warndecl
+#define __warndecl(name, msg) \
+  extern void name (void) __attribute__ ((alias ("nop"))) attribute_hidden; \
+  link_warning (name, msg)
+
+#undef	__USE_FORTIFY_LEVEL
+#define __USE_FORTIFY_LEVEL 99
+
+/* Following here we need an #include for each public header file
+   that uses __warndecl.  */
+
+#include <string.h>