]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
* debug/chk_fail.c: Include errno.h and string.h.
authorJakub Jelinek <jakub@redhat.com>
Fri, 12 Nov 2004 16:57:17 +0000 (16:57 +0000)
committerJakub Jelinek <jakub@redhat.com>
Fri, 12 Nov 2004 16:57:17 +0000 (16:57 +0000)
(__chk_fail): Write a short message to stderr.
* debug/tst-chk1.c: Include fcntl.h.
(do_test): Redirect stderr to /dev/null.
* debug/test-strcpy_chk.c: Include fcntl.h.
(test_main): Redirect stderr to /dev/null.
(do_one_test, do_random_tests): Use printf instead of
error.

ChangeLog
debug/chk_fail.c
debug/test-strcpy_chk.c
debug/tst-chk1.c

index 7b36bcfa8c20c03e457c24d90790788cbe34d8b7..37146aade27c56cbfa2aa67b0bae82678f13113b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-11-11  Jakub Jelinek  <jakub@redhat.com>
+
+       * debug/chk_fail.c: Include errno.h and string.h.
+       (__chk_fail): Write a short message to stderr.
+       * debug/tst-chk1.c: Include fcntl.h.
+       (do_test): Redirect stderr to /dev/null.
+       * debug/test-strcpy_chk.c: Include fcntl.h.
+       (test_main): Redirect stderr to /dev/null.
+       (do_one_test, do_random_tests): Use printf instead of
+       error.
+
 2004-11-12  Ulrich Drepper  <drepper@redhat.com>
 
        * posix/Makefile (tests): Add bug-regex24.
index 48848fbe35464c120fe800655bac28047889c3d2..70ffa9e40fc1710240924486511ea7188c3de6ee 100644 (file)
@@ -16,7 +16,9 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <errno.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <abort-instr.h>
 
@@ -27,6 +29,8 @@ __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
index 4c61f4fb432c6d591f35aad50bc20848258cc1f5..8430ca47041eb2e2dc5197279af0eff660f04ae4 100644 (file)
@@ -48,6 +48,7 @@ simple_strcpy_chk (char *dst, const char *src, size_t len)
 
 #include <setjmp.h>
 #include <signal.h>
+#include <fcntl.h>
 
 volatile int chk_fail_ok;
 jmp_buf chk_fail_buf;
@@ -80,8 +81,8 @@ do_one_test (impl_t *impl, char *dst, const char *src,
       if (setjmp (chk_fail_buf) == 0)
        {
          res = CALL (impl, dst, src, dlen);
-         error (0, 0, "Function %s (%zd; %zd) did not __chk_fail",
-                impl->name, len, dlen);
+         printf ("*** Function %s (%zd; %zd) did not __chk_fail",
+                 impl->name, len, dlen);
          chk_fail_ok = 0;
          ret = 1;
        }
@@ -92,16 +93,16 @@ do_one_test (impl_t *impl, char *dst, const char *src,
 
   if (res != STRCPY_RESULT (dst, len))
     {
-      error (0, 0, "Wrong result in function %s %p %p", impl->name,
-            res, STRCPY_RESULT (dst, len));
+      printf ("*** Wrong result in function %s %p %p", impl->name,
+             res, STRCPY_RESULT (dst, len));
       ret = 1;
       return;
     }
 
   if (strcmp (dst, src) != 0)
     {
-      error (0, 0, "Wrong result in function %s dst \"%s\" src \"%s\"",
-            impl->name, dst, src);
+      printf ("*** Wrong result in function %s dst \"%s\" src \"%s\"",
+             impl->name, dst, src);
       ret = 1;
       return;
     }
@@ -232,7 +233,7 @@ do_random_tests (void)
                  if (setjmp (chk_fail_buf) == 0)
                    {
                      res = CALL (impl, p2 + align2, p1 + align1, dlen);
-                     error (0, 0, "Iteration %zd - did not __chk_fail", n);
+                     printf ("*** Iteration %zd - did not __chk_fail", n);
                      chk_fail_ok = 0;
                      ret = 1;
                    }
@@ -243,17 +244,17 @@ do_random_tests (void)
          res = CALL (impl, p2 + align2, p1 + align1, dlen);
          if (res != STRCPY_RESULT (p2 + align2, len))
            {
-             error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %zd, %zd) %p != %p",
-                    n, impl->name, align1, align2, len, res,
-                    STRCPY_RESULT (p2 + align2, len));
+             printf ("*** Iteration %zd - wrong result in function %s (%zd, %zd, %zd) %p != %p",
+                     n, impl->name, align1, align2, len, res,
+                     STRCPY_RESULT (p2 + align2, len));
              ret = 1;
            }
          for (j = 0; j < align2 + 64; ++j)
            {
              if (p2[j - 64] != '\1')
                {
-                 error (0, 0, "Iteration %zd - garbage before, %s (%zd, %zd, %zd)",
-                        n, impl->name, align1, align2, len);
+                 printf ("*** Iteration %zd - garbage before, %s (%zd, %zd, %zd)",
+                         n, impl->name, align1, align2, len);
                  ret = 1;
                  break;
                }
@@ -262,16 +263,16 @@ do_random_tests (void)
            {
              if (p2[j] != '\1')
                {
-                 error (0, 0, "Iteration %zd - garbage after, %s (%zd, %zd, %zd)",
-                        n, impl->name, align1, align2, len);
+                 printf ("*** Iteration %zd - garbage after, %s (%zd, %zd, %zd)",
+                         n, impl->name, align1, align2, len);
                  ret = 1;
                  break;
                }
            }
          if (memcmp (p1 + align1, p2 + align2, len + 1))
            {
-             error (0, 0, "Iteration %zd - different strings, %s (%zd, %zd, %zd)",
-                    n, impl->name, align1, align2, len);
+             printf ("*** Iteration %zd - different strings, %s (%zd, %zd, %zd)",
+                     n, impl->name, align1, align2, len);
              ret = 1;
            }
        }
@@ -290,6 +291,10 @@ test_main (void)
 
   sigaction (SIGABRT, &sa, NULL);
 
+  /* Avoid all the buffer overflow messages on stderr.  */
+  close (STDERR_FILENO);
+  open ("/dev/null", O_WRONLY);
+
   test_init ();
 
   printf ("%23s", "");
index 9c9f82a3af9f51a9d83ee28cc0765d76b4dcd875..e01284ae53c725300c9ad312c1c9c50f0cd04f3b 100644 (file)
@@ -17,6 +17,7 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <fcntl.h>
 #include <setjmp.h>
 #include <signal.h>
 #include <stdio.h>
@@ -106,6 +107,10 @@ do_test (void)
 
   sigaction (SIGABRT, &sa, NULL);
 
+  /* Avoid all the buffer overflow messages on stderr.  */
+  close (STDERR_FILENO);
+  open ("/dev/null", O_WRONLY);
+
   struct A { char buf1[9]; char buf2[1]; } a;
 
   printf ("Test checking routines at fortify level %d\n",