about summary refs log tree commit diff
path: root/misc
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2016-02-12 12:57:40 +0100
committerFlorian Weimer <fweimer@redhat.com>2016-02-12 12:57:40 +0100
commitf34f146e682d8d529dcf64b3c2781bf3f2f05f6c (patch)
tree44d3d7edcd18bbae911b40e2ba646ca3e38c1849 /misc
parente535ce250143b9c1600b306911710c0de73e2a5e (diff)
downloadglibc-f34f146e682d8d529dcf64b3c2781bf3f2f05f6c.tar.gz
glibc-f34f146e682d8d529dcf64b3c2781bf3f2f05f6c.tar.xz
glibc-f34f146e682d8d529dcf64b3c2781bf3f2f05f6c.zip
hsearch_r: Apply VM size limit in test case
Diffstat (limited to 'misc')
-rw-r--r--misc/bug18240.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/misc/bug18240.c b/misc/bug18240.c
index 4b26865a31..773586ee10 100644
--- a/misc/bug18240.c
+++ b/misc/bug18240.c
@@ -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);