arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

Blame SOURCES/glibc-rh1647490-1.patch

147e83
commit 6c3a8a9d868a8deddf0d6dcc785b6d120de90523
147e83
Author: Paul Pluzhnikov <ppluzhnikov@kazbek.mtv.corp.google.com>
147e83
Date:   Fri Aug 24 18:08:51 2018 -0700
147e83
147e83
    Fix BZ#23400 (creating temporary files in source tree), and undefined behavior in test.
147e83
147e83
diff --git a/stdlib/test-bz22786.c b/stdlib/test-bz22786.c
147e83
index e7837f98c19fc4bf..d1aa69106ccf6ac5 100644
147e83
--- a/stdlib/test-bz22786.c
147e83
+++ b/stdlib/test-bz22786.c
147e83
@@ -26,28 +26,20 @@
147e83
 #include <unistd.h>
147e83
 #include <sys/stat.h>
147e83
 #include <sys/types.h>
147e83
+#include <support/check.h>
147e83
+#include <support/support.h>
147e83
+#include <support/temp_file.h>
147e83
 #include <support/test-driver.h>
147e83
 #include <libc-diag.h>
147e83
 
147e83
 static int
147e83
 do_test (void)
147e83
 {
147e83
-  const char dir[] = "bz22786";
147e83
-  const char lnk[] = "bz22786/symlink";
147e83
+  const char *dir = support_create_temp_directory ("bz22786.");
147e83
+  const char *lnk = xasprintf ("%s/symlink", dir);
147e83
+  const size_t path_len = (size_t) INT_MAX + strlen (lnk) + 1;
147e83
 
147e83
-  rmdir (dir);
147e83
-  if (mkdir (dir, 0755) != 0 && errno != EEXIST)
147e83
-    {
147e83
-      printf ("mkdir %s: %m\n", dir);
147e83
-      return EXIT_FAILURE;
147e83
-    }
147e83
-  if (symlink (".", lnk) != 0 && errno != EEXIST)
147e83
-    {
147e83
-      printf ("symlink (%s, %s): %m\n", dir, lnk);
147e83
-      return EXIT_FAILURE;
147e83
-    }
147e83
-
147e83
-  const size_t path_len = (size_t) INT_MAX + 1;
147e83
+  TEST_VERIFY_EXIT (symlink (".", lnk) == 0);
147e83
 
147e83
   DIAG_PUSH_NEEDS_COMMENT;
147e83
 #if __GNUC_PREREQ (7, 0)
147e83
@@ -55,20 +47,14 @@ do_test (void)
147e83
      allocation to succeed for the test to work.  */
147e83
   DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
147e83
 #endif
147e83
-  char *path = malloc (path_len);
147e83
+  char *path = xmalloc (path_len);
147e83
   DIAG_POP_NEEDS_COMMENT;
147e83
 
147e83
-  if (path == NULL)
147e83
-    {
147e83
-      printf ("malloc (%zu): %m\n", path_len);
147e83
-      return EXIT_UNSUPPORTED;
147e83
-    }
147e83
-
147e83
-  /* Construct very long path = "bz22786/symlink/aaaa....."  */
147e83
-  char *p = mempcpy (path, lnk, sizeof (lnk) - 1);
147e83
+  /* Construct very long path = "/tmp/bz22786.XXXX/symlink/aaaa....."  */
147e83
+  char *p = mempcpy (path, lnk, strlen (lnk));
147e83
   *(p++) = '/';
147e83
-  memset (p, 'a', path_len - (path - p) - 2);
147e83
-  p[path_len - (path - p) - 1] = '\0';
147e83
+  memset (p, 'a', path_len - (p - path) - 2);
147e83
+  p[path_len - (p - path) - 1] = '\0';
147e83
 
147e83
   /* This call crashes before the fix for bz22786 on 32-bit platforms.  */
147e83
   p = realpath (path, NULL);
147e83
@@ -81,7 +67,6 @@ do_test (void)
147e83
 
147e83
   /* Cleanup.  */
147e83
   unlink (lnk);
147e83
-  rmdir (dir);
147e83
 
147e83
   return 0;
147e83
 }