]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - debug/test-strcpy_chk.c
Fix REALLOC_ZERO_BYTES_FREES comment to match C17
[thirdparty/glibc.git] / debug / test-strcpy_chk.c
index 62a581d19090f2903b6f476e2bb338ac6e495d42..80c07482aaa54e3bb7ae28e9972a48f65e179209 100644 (file)
@@ -1,5 +1,5 @@
 /* Test and measure __strcpy_chk functions.
-   Copyright (C) 1999-2014 Free Software Foundation, Inc.
+   Copyright (C) 1999-2021 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
@@ -15,7 +15,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
 #ifndef STRCPY_RESULT
 # define STRCPY_RESULT(dst, len) dst
@@ -54,6 +54,11 @@ simple_strcpy_chk (char *dst, const char *src, size_t len)
 #include <setjmp.h>
 #include <signal.h>
 
+static int test_main (void);
+#define TEST_FUNCTION test_main
+#include <support/test-driver.c>
+#include <support/support.h>
+
 volatile int chk_fail_ok;
 jmp_buf chk_fail_buf;
 
@@ -266,28 +271,12 @@ Iteration %zd - different strings, %s (%zd, %zd, %zd)\n",
     }
 }
 
-int
+static int
 test_main (void)
 {
   size_t i;
 
-  struct sigaction sa;
-  sa.sa_handler = handler;
-  sa.sa_flags = 0;
-  sigemptyset (&sa.sa_mask);
-
-  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);
+  set_fortify_handler (handler);
 
   test_init ();
 
@@ -365,5 +354,3 @@ test_main (void)
   do_random_tests ();
   return ret;
 }
-
-#include "../test-skeleton.c"