mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-22 13:00:06 +00:00
Fix BZ#23400 (creating temporary files in source tree), and undefined behavior in test.
This commit is contained in:
parent
895ef79e04
commit
6c3a8a9d86
@ -1,3 +1,9 @@
|
|||||||
|
2018-08-24 Paul Pluzhnikov <ppluzhnikov@google.com>
|
||||||
|
|
||||||
|
[BZ #23400]
|
||||||
|
* stdlib/test-bz22786.c (do_test): Fix undefined behavior, don't
|
||||||
|
create temporary files in source tree.
|
||||||
|
|
||||||
2018-08-24 Joseph Myers <joseph@codesourcery.com>
|
2018-08-24 Joseph Myers <joseph@codesourcery.com>
|
||||||
|
|
||||||
* sysdeps/generic/math-tests-trap.h: New file.
|
* sysdeps/generic/math-tests-trap.h: New file.
|
||||||
|
@ -26,28 +26,20 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <support/check.h>
|
||||||
|
#include <support/support.h>
|
||||||
|
#include <support/temp_file.h>
|
||||||
#include <support/test-driver.h>
|
#include <support/test-driver.h>
|
||||||
#include <libc-diag.h>
|
#include <libc-diag.h>
|
||||||
|
|
||||||
static int
|
static int
|
||||||
do_test (void)
|
do_test (void)
|
||||||
{
|
{
|
||||||
const char dir[] = "bz22786";
|
const char *dir = support_create_temp_directory ("bz22786.");
|
||||||
const char lnk[] = "bz22786/symlink";
|
const char *lnk = xasprintf ("%s/symlink", dir);
|
||||||
|
const size_t path_len = (size_t) INT_MAX + strlen (lnk) + 1;
|
||||||
|
|
||||||
rmdir (dir);
|
TEST_VERIFY_EXIT (symlink (".", lnk) == 0);
|
||||||
if (mkdir (dir, 0755) != 0 && errno != EEXIST)
|
|
||||||
{
|
|
||||||
printf ("mkdir %s: %m\n", dir);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
if (symlink (".", lnk) != 0 && errno != EEXIST)
|
|
||||||
{
|
|
||||||
printf ("symlink (%s, %s): %m\n", dir, lnk);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t path_len = (size_t) INT_MAX + 1;
|
|
||||||
|
|
||||||
DIAG_PUSH_NEEDS_COMMENT;
|
DIAG_PUSH_NEEDS_COMMENT;
|
||||||
#if __GNUC_PREREQ (7, 0)
|
#if __GNUC_PREREQ (7, 0)
|
||||||
@ -55,20 +47,14 @@ do_test (void)
|
|||||||
allocation to succeed for the test to work. */
|
allocation to succeed for the test to work. */
|
||||||
DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
|
DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
|
||||||
#endif
|
#endif
|
||||||
char *path = malloc (path_len);
|
char *path = xmalloc (path_len);
|
||||||
DIAG_POP_NEEDS_COMMENT;
|
DIAG_POP_NEEDS_COMMENT;
|
||||||
|
|
||||||
if (path == NULL)
|
/* Construct very long path = "/tmp/bz22786.XXXX/symlink/aaaa....." */
|
||||||
{
|
char *p = mempcpy (path, lnk, strlen (lnk));
|
||||||
printf ("malloc (%zu): %m\n", path_len);
|
|
||||||
return EXIT_UNSUPPORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Construct very long path = "bz22786/symlink/aaaa....." */
|
|
||||||
char *p = mempcpy (path, lnk, sizeof (lnk) - 1);
|
|
||||||
*(p++) = '/';
|
*(p++) = '/';
|
||||||
memset (p, 'a', path_len - (path - p) - 2);
|
memset (p, 'a', path_len - (p - path) - 2);
|
||||||
p[path_len - (path - p) - 1] = '\0';
|
p[path_len - (p - path) - 1] = '\0';
|
||||||
|
|
||||||
/* This call crashes before the fix for bz22786 on 32-bit platforms. */
|
/* This call crashes before the fix for bz22786 on 32-bit platforms. */
|
||||||
p = realpath (path, NULL);
|
p = realpath (path, NULL);
|
||||||
@ -81,7 +67,6 @@ do_test (void)
|
|||||||
|
|
||||||
/* Cleanup. */
|
/* Cleanup. */
|
||||||
unlink (lnk);
|
unlink (lnk);
|
||||||
rmdir (dir);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user