00db10
commit 3bad2358d67d371497079bba4f8eca9c0096f4e2
00db10
Author: Stefan Liebler <stli@linux.ibm.com>
00db10
Date:   Thu Aug 30 08:44:32 2018 +0200
00db10
00db10
    Test stdlib/test-bz22786 exits now with unsupported if malloc fails.
00db10
    
00db10
    The test tries to allocate more than 2^31 bytes which will always fail on s390
00db10
    as it has maximum 2^31bit of memory.
00db10
    Before commit 6c3a8a9d868a8deddf0d6dcc785b6d120de90523, this test returned
00db10
    unsupported if malloc fails.  This patch re enables this behaviour.
00db10
    
00db10
    Furthermore support_delete_temp_files() failed to remove the temp directory
00db10
    in this case as it is not empty due to the created symlink.
00db10
    Thus the creation of the symlink is moved behind malloc.
00db10
    
00db10
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
00db10
    
00db10
    ChangeLog:
00db10
    
00db10
            * stdlib/test-bz22786.c (do_test): Return EXIT_UNSUPPORTED
00db10
            if malloc fails.
00db10
00db10
diff --git a/stdlib/test-bz22786.c b/stdlib/test-bz22786.c
00db10
index d1aa69106ccf6ac5..777bf9180f4b5022 100644
00db10
--- a/stdlib/test-bz22786.c
00db10
+++ b/stdlib/test-bz22786.c
00db10
@@ -39,16 +39,25 @@ do_test (void)
00db10
   const char *lnk = xasprintf ("%s/symlink", dir);
00db10
   const size_t path_len = (size_t) INT_MAX + strlen (lnk) + 1;
00db10
 
00db10
-  TEST_VERIFY_EXIT (symlink (".", lnk) == 0);
00db10
-
00db10
   DIAG_PUSH_NEEDS_COMMENT;
00db10
 #if __GNUC_PREREQ (7, 0)
00db10
   /* GCC 7 warns about too-large allocations; here we need such
00db10
      allocation to succeed for the test to work.  */
00db10
   DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
00db10
 #endif
00db10
-  char *path = xmalloc (path_len);
00db10
+  char *path = malloc (path_len);
00db10
   DIAG_POP_NEEDS_COMMENT;
00db10
+  if (path == NULL)
00db10
+    {
00db10
+      printf ("malloc (%zu): %m\n", path_len);
00db10
+      /* On 31-bit s390 the malloc will always fail as we do not have
00db10
+	 so much memory, and we want to mark the test unsupported.
00db10
+	 Likewise on systems with little physical memory the test will
00db10
+	 fail and should be unsupported.  */
00db10
+      return EXIT_UNSUPPORTED;
00db10
+    }
00db10
+
00db10
+  TEST_VERIFY_EXIT (symlink (".", lnk) == 0);
00db10
 
00db10
   /* Construct very long path = "/tmp/bz22786.XXXX/symlink/aaaa....."  */
00db10
   char *p = mempcpy (path, lnk, strlen (lnk));