From patchwork Mon Feb 8 12:41:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 10758 Received: (qmail 46897 invoked by alias); 8 Feb 2016 12:41:26 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 46886 invoked by uid 89); 8 Feb 2016 12:41:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Apply, impacting, Hx-languages-length:1067 X-HELO: mx1.redhat.com To: GNU C Library From: Florian Weimer Subject: [PATCH] hsearch_r: Apply VM size limit in test case Message-ID: <56B88CF0.40809@redhat.com> Date: Mon, 8 Feb 2016 13:41:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 As discussed before. Florian 2016-02-08 Florian Weimer * misc/bug18240.c (do_test): Set RLIMIT_AS. diff --git a/misc/bug18240.c b/misc/bug18240.c index 4b26865..773586e 100644 --- a/misc/bug18240.c +++ b/misc/bug18240.c @@ -22,6 +22,7 @@ #include #include #include +#include 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);