From patchwork Tue Dec 3 23:09:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DJ Delorie X-Patchwork-Id: 36487 Received: (qmail 96729 invoked by alias); 3 Dec 2019 23:09:24 -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 96721 invoked by uid 89); 3 Dec 2019 23:09:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575414561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cWFYwpBxVvjMFKFV3vwZLMLQk1SD3e5KBUKfH25gYMQ=; b=BT084nHzcFD99KUDPOiIgBWi5erH4qezP76itxPmy7OIuga7cC/FblpUVyDE5qIkbXiGHy d30baATitIonl9+mvbsKl7i1bGh1Y3lD+UHxINu6j4gdzmLJBFe5h9iDLBkXs64YgAxMr1 9HXVT4OSIH+qeNOA1tYLkoWmbKEaFQw= Date: Tue, 03 Dec 2019 18:09:12 -0500 Message-Id: From: DJ Delorie To: libc-alpha@sourceware.org Subject: [patch] Correct range checking in mallopt/mxfast/tcache [BZ #25194] X-Mimecast-Spam-Score: 0 From 2da566d7d7c956658d1d6009875ceab85b3d190b Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Tue, 3 Dec 2019 17:44:36 -0500 Subject: Correct range checking in mallopt/mxfast/tcache [BZ #25194] do_set_tcache_max, do_set_mxfast: Fix two instances of comparing "size_t < 0" Both cases have upper limit, so the "negative value" case is already handled via (undefined) overflow semantics. mallopt: pass return value of do_set_mxfast to user. diff --git a/malloc/malloc.c b/malloc/malloc.c index 70cc35a473..ed16a72dbd 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -5086,13 +5086,14 @@ do_set_arena_max (size_t value) static __always_inline int do_set_tcache_max (size_t value) { - if (value >= 0 && value <= MAX_TCACHE_SIZE) + if (value <= MAX_TCACHE_SIZE) { LIBC_PROBE (memory_tunable_tcache_max_bytes, 2, value, mp_.tcache_max_bytes); mp_.tcache_max_bytes = value; mp_.tcache_bins = csize2tidx (request2size(value)) + 1; + return 1; } - return 1; + return 0; } static __always_inline int @@ -5102,8 +5103,9 @@ do_set_tcache_count (size_t value) { LIBC_PROBE (memory_tunable_tcache_count, 2, value, mp_.tcache_count); mp_.tcache_count = value; + return 1; } - return 1; + return 0; } static __always_inline int @@ -5119,7 +5121,7 @@ static inline int __always_inline do_set_mxfast (size_t value) { - if (value >= 0 && value <= MAX_FAST_SIZE) + if (value <= MAX_FAST_SIZE) { LIBC_PROBE (memory_mallopt_mxfast, 2, value, get_max_fast ()); set_max_fast (value); @@ -5147,7 +5149,7 @@ __libc_mallopt (int param_number, int value) switch (param_number) { case M_MXFAST: - do_set_mxfast (value); + res = do_set_mxfast (value); break; case M_TRIM_THRESHOLD: