about summary refs log tree commit diff
path: root/debug
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2004-11-15 09:47:23 +0000
committerJakub Jelinek <jakub@redhat.com>2004-11-15 09:47:23 +0000
commitb3c20a361d75caf75f670b2fcd64ab8668c16ca5 (patch)
treecac006e13628dcbf5a48cb618417ae708906db89 /debug
parent87ffc9aca119436c8530d6605483a49cfb16668e (diff)
downloadglibc-b3c20a361d75caf75f670b2fcd64ab8668c16ca5.tar.gz
glibc-b3c20a361d75caf75f670b2fcd64ab8668c16ca5.tar.xz
glibc-b3c20a361d75caf75f670b2fcd64ab8668c16ca5.zip
Updated to fedora-glibc-20041115T0915
Diffstat (limited to 'debug')
-rw-r--r--debug/chk_fail.c18
-rw-r--r--debug/test-strcpy_chk.c36
-rw-r--r--debug/tst-chk1.c16
3 files changed, 39 insertions, 31 deletions
diff --git a/debug/chk_fail.c b/debug/chk_fail.c
index 70ffa9e40f..dc1c3d70b6 100644
--- a/debug/chk_fail.c
+++ b/debug/chk_fail.c
@@ -1,3 +1,4 @@
+
 /* Copyright (C) 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,27 +17,14 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
-#include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <abort-instr.h>
 
 
 void
 __attribute__ ((noreturn))
 __chk_fail (void)
 {
-  while (1)
-    {
-      const char *text = "*** buffer overflow detected ***\n";
-      TEMP_FAILURE_RETRY (write (STDERR_FILENO, text, strlen (text)));
-      /* This will leave a nice backtrace.  */
-      abort ();
-#ifdef ABORT_INSTRUCTION
-      ABORT_INSTRUCTION;
-#endif
-      _exit (127);
-    }
+  __libc_fatal ("*** buffer overflow detected ***\n");
 }
 libc_hidden_def (__chk_fail)
diff --git a/debug/test-strcpy_chk.c b/debug/test-strcpy_chk.c
index 8430ca4704..ac9f9448cf 100644
--- a/debug/test-strcpy_chk.c
+++ b/debug/test-strcpy_chk.c
@@ -46,9 +46,10 @@ simple_strcpy_chk (char *dst, const char *src, size_t len)
 }
 #endif
 
+#include <fcntl.h>
+#include <paths.h>
 #include <setjmp.h>
 #include <signal.h>
-#include <fcntl.h>
 
 volatile int chk_fail_ok;
 jmp_buf chk_fail_buf;
@@ -81,8 +82,8 @@ do_one_test (impl_t *impl, char *dst, const char *src,
       if (setjmp (chk_fail_buf) == 0)
 	{
 	  res = CALL (impl, dst, src, dlen);
-	  printf ("*** Function %s (%zd; %zd) did not __chk_fail",
-	          impl->name, len, dlen);
+	  printf ("*** Function %s (%zd; %zd) did not __chk_fail\n",
+		  impl->name, len, dlen);
 	  chk_fail_ok = 0;
 	  ret = 1;
 	}
@@ -93,7 +94,7 @@ do_one_test (impl_t *impl, char *dst, const char *src,
 
   if (res != STRCPY_RESULT (dst, len))
     {
-      printf ("*** Wrong result in function %s %p %p", impl->name,
+      printf ("Wrong result in function %s %p %p\n", impl->name,
 	      res, STRCPY_RESULT (dst, len));
       ret = 1;
       return;
@@ -101,7 +102,7 @@ do_one_test (impl_t *impl, char *dst, const char *src,
 
   if (strcmp (dst, src) != 0)
     {
-      printf ("*** Wrong result in function %s dst \"%s\" src \"%s\"",
+      printf ("Wrong result in function %s dst \"%s\" src \"%s\"\n",
 	      impl->name, dst, src);
       ret = 1;
       return;
@@ -233,7 +234,7 @@ do_random_tests (void)
 		  if (setjmp (chk_fail_buf) == 0)
 		    {
 		      res = CALL (impl, p2 + align2, p1 + align1, dlen);
-		      printf ("*** Iteration %zd - did not __chk_fail", n);
+		      printf ("Iteration %zd - did not __chk_fail\n", n);
 		      chk_fail_ok = 0;
 		      ret = 1;
 		    }
@@ -244,7 +245,8 @@ do_random_tests (void)
 	  res = CALL (impl, p2 + align2, p1 + align1, dlen);
 	  if (res != STRCPY_RESULT (p2 + align2, len))
 	    {
-	      printf ("*** Iteration %zd - wrong result in function %s (%zd, %zd, %zd) %p != %p",
+	      printf ("\
+Iteration %zd - wrong result in function %s (%zd, %zd, %zd) %p != %p\n",
 		      n, impl->name, align1, align2, len, res,
 		      STRCPY_RESULT (p2 + align2, len));
 	      ret = 1;
@@ -253,7 +255,8 @@ do_random_tests (void)
 	    {
 	      if (p2[j - 64] != '\1')
 		{
-		  printf ("*** Iteration %zd - garbage before, %s (%zd, %zd, %zd)",
+		  printf ("\
+Iteration %zd - garbage before, %s (%zd, %zd, %zd)\n",
 			  n, impl->name, align1, align2, len);
 		  ret = 1;
 		  break;
@@ -263,7 +266,8 @@ do_random_tests (void)
 	    {
 	      if (p2[j] != '\1')
 		{
-		  printf ("*** Iteration %zd - garbage after, %s (%zd, %zd, %zd)",
+		  printf ("\
+Iteration %zd - garbage after, %s (%zd, %zd, %zd)\n",
 			  n, impl->name, align1, align2, len);
 		  ret = 1;
 		  break;
@@ -271,7 +275,8 @@ do_random_tests (void)
 	    }
 	  if (memcmp (p1 + align1, p2 + align2, len + 1))
 	    {
-	      printf ("*** Iteration %zd - different strings, %s (%zd, %zd, %zd)",
+	      printf ("\
+Iteration %zd - different strings, %s (%zd, %zd, %zd)\n",
 		      n, impl->name, align1, align2, len);
 	      ret = 1;
 	    }
@@ -292,8 +297,15 @@ test_main (void)
   sigaction (SIGABRT, &sa, NULL);
 
   /* Avoid all the buffer overflow messages on stderr.  */
-  close (STDERR_FILENO);
-  open ("/dev/null", O_WRONLY);
+  int fd = open (_PATH_DEVNULL, O_WRONLY);
+  if (fd == -1)
+    close (STDERR_FILENO);
+  else
+    {
+      dup2 (fd, STDERR_FILENO);
+      close (fd);
+    }
+  setenv ("LIBC_FATAL_STDERR_", "1", 1);
 
   test_init ();
 
diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c
index e01284ae53..37320c3514 100644
--- a/debug/tst-chk1.c
+++ b/debug/tst-chk1.c
@@ -18,6 +18,7 @@
    02111-1307 USA.  */
 
 #include <fcntl.h>
+#include <paths.h>
 #include <setjmp.h>
 #include <signal.h>
 #include <stdio.h>
@@ -108,8 +109,15 @@ do_test (void)
   sigaction (SIGABRT, &sa, NULL);
 
   /* Avoid all the buffer overflow messages on stderr.  */
-  close (STDERR_FILENO);
-  open ("/dev/null", O_WRONLY);
+  int fd = open (_PATH_DEVNULL, O_WRONLY);
+  if (fd == -1)
+    close (STDERR_FILENO);
+  else
+    {
+      dup2 (fd, STDERR_FILENO);
+      close (fd);
+    }
+  setenv ("LIBC_FATAL_STDERR_", "1", 1);
 
   struct A { char buf1[9]; char buf2[1]; } a;
 
@@ -205,7 +213,7 @@ do_test (void)
   if (memcmp (a.buf1, "aabcdabcjj", 10))
     FAIL ();
 
-#if __USE_FORTIFY_LEVEL < 2 || !__GNUC_PREREQ (4, 0)
+#if __USE_FORTIFY_LEVEL < 2
   /* The following tests are supposed to crash with -D_FORTIFY_SOURCE=2
      and sufficient GCC support, as the string operations overflow
      from a.buf1 into a.buf2.  */
@@ -304,7 +312,7 @@ do_test (void)
   memset (a.buf1 + 9, 'j', l0 + 2);
   CHK_FAIL_END
 
-#if __USE_FORTIFY_LEVEL >= 2 && __GNUC_PREREQ (4, 0)
+#if __USE_FORTIFY_LEVEL >= 2
 # define O 0
 #else
 # define O 1