aboutsummaryrefslogtreecommitdiff
path: root/debug
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-11-13 03:13:00 +0000
committerUlrich Drepper <drepper@redhat.com>2004-11-13 03:13:00 +0000
commita9055cab7ac609b96984179194c7a2ec410c8e2b (patch)
treed7bbccb32e96d87220932549049a48f3eb5c3dad /debug
parent1327439fc6ef182c3ab8c69a55d3bee15b3c62a7 (diff)
downloadglibc-a9055cab7ac609b96984179194c7a2ec410c8e2b.zip
glibc-a9055cab7ac609b96984179194c7a2ec410c8e2b.tar.gz
glibc-a9055cab7ac609b96984179194c7a2ec410c8e2b.tar.bz2
Update.
2004-11-12 Ulrich Drepper <drepper@redhat.com> * sysdeps/unix/sysv/linux/libc_fatal.c: Add new function __libc_message which performs the printing and simple format string handling. The string is written to tty, stderr, syslog in this order, stopping after the first successful output. (__libc_fatal): Call __libc_message. * include/stdio.h: Declare __libc_message. * malloc/malloc.c (malloc_printerr): Use __libc_message. * debug/chk_fail.c: Also print message with __libc_message. * debug/test-strcpy_chk.c: Ensure that debug messages are not printed to the terminal or stderr. * debug/tst-chk1.c: Likewise. * posix/Makefile: Remove gpl2lgpl variable.
Diffstat (limited to 'debug')
-rw-r--r--debug/chk_fail.c14
-rw-r--r--debug/test-strcpy_chk.c49
-rw-r--r--debug/tst-chk1.c13
3 files changed, 49 insertions, 27 deletions
diff --git a/debug/chk_fail.c b/debug/chk_fail.c
index 48848fb..dc1c3d7 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,23 +17,14 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <abort-instr.h>
void
__attribute__ ((noreturn))
__chk_fail (void)
{
- while (1)
- {
- /* 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 4c61f4f..ac9f944 100644
--- a/debug/test-strcpy_chk.c
+++ b/debug/test-strcpy_chk.c
@@ -46,6 +46,8 @@ simple_strcpy_chk (char *dst, const char *src, size_t len)
}
#endif
+#include <fcntl.h>
+#include <paths.h>
#include <setjmp.h>
#include <signal.h>
@@ -80,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);
- error (0, 0, "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;
}
@@ -92,16 +94,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\n", 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\"\n",
+ impl->name, dst, src);
ret = 1;
return;
}
@@ -232,7 +234,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", n);
chk_fail_ok = 0;
ret = 1;
}
@@ -243,17 +245,19 @@ 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",
+ 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",
+ n, impl->name, align1, align2, len);
ret = 1;
break;
}
@@ -262,16 +266,18 @@ 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",
+ 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",
+ n, impl->name, align1, align2, len);
ret = 1;
}
}
@@ -290,6 +296,17 @@ test_main (void)
sigaction (SIGABRT, &sa, NULL);
+ /* Avoid all the buffer overflow messages on stderr. */
+ 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 ();
printf ("%23s", "");
diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c
index fb2074d..37320c3 100644
--- a/debug/tst-chk1.c
+++ b/debug/tst-chk1.c
@@ -17,6 +17,8 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <fcntl.h>
+#include <paths.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
@@ -106,6 +108,17 @@ do_test (void)
sigaction (SIGABRT, &sa, NULL);
+ /* Avoid all the buffer overflow messages on stderr. */
+ 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;
printf ("Test checking routines at fortify level %d\n",