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