]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hsearch_r: Apply VM size limit in test case
authorFlorian Weimer <fweimer@redhat.com>
Fri, 12 Feb 2016 11:57:40 +0000 (12:57 +0100)
committerGabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
Tue, 24 May 2016 14:37:51 +0000 (11:37 -0300)
(cherry picked from commit f34f146e682d8d529dcf64b3c2781bf3f2f05f6c)

ChangeLog
misc/bug18240.c

index cd343c7090203d58918a0ef65a3bb16b967a80e7..c2b1307d4df9c6e0bcf2f68278c72a8f0366552b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-05-24  Florian Weimer  <fweimer@redhat.com>
+
+       * misc/bug18240.c (do_test): Set RLIMIT_AS.
+
 2016-05-24  Paul Eggert  <eggert@cs.ucla.edu>
 
        [BZ #18240]
index 4b26865a316424edf1cb76012231ea15f679420c..773586ee1051a924910e1175fd3bb39499599861 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/resource.h>
 
 static void
 test_size (size_t size)
@@ -58,6 +59,27 @@ test_size (size_t size)
 static int
 do_test (void)
 {
+  /* Limit the size of the process, so that memory allocation will
+     fail without impacting the entire system.  */
+  {
+    struct rlimit limit;
+    if (getrlimit (RLIMIT_AS, &limit) != 0)
+      {
+        printf ("getrlimit (RLIMIT_AS) failed: %m\n");
+        return 1;
+      }
+    long target = 100 * 1024 * 1024;
+    if (limit.rlim_cur == RLIM_INFINITY || limit.rlim_cur > target)
+      {
+        limit.rlim_cur = target;
+        if (setrlimit (RLIMIT_AS, &limit) != 0)
+          {
+            printf ("setrlimit (RLIMIT_AS) failed: %m\n");
+            return 1;
+          }
+      }
+  }
+
   test_size (500);
   test_size (-1);
   test_size (-3);