From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id DF8721F8C6 for ; Wed, 28 Jul 2021 17:47:44 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D23F9399E00E for ; Wed, 28 Jul 2021 17:47:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D23F9399E00E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1627494463; bh=qVZtlBjxtJPQQ9cJaRATG9Xd5AZyIgMXFj7UlAUPJs4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yfwdeoL+zC0VQ4Du91NQrgJm7oQOyKN+TvKC2xRyrDMFX3K24En9j7Ld9LOXSgOFw QXazBPG85mfigDiuzBnpSgBSQl2Rwzj1Mqgq94W1cTjEu9qkFkhSlvDCQbLpqSfuen qp9Yr56mPn0sOUq4fjzqNl/ou3qO1+75N2hQQHpM= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 66BFD399E03D for ; Wed, 28 Jul 2021 17:47:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 66BFD399E03D Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-588-FBB3IDoNOrWfYdY3Il-jmQ-1; Wed, 28 Jul 2021 13:47:05 -0400 X-MC-Unique: FBB3IDoNOrWfYdY3Il-jmQ-1 Received: by mail-qk1-f200.google.com with SMTP id bm25-20020a05620a1999b02903a9c3f8b89fso2117534qkb.2 for ; Wed, 28 Jul 2021 10:47:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-disposition; bh=qVZtlBjxtJPQQ9cJaRATG9Xd5AZyIgMXFj7UlAUPJs4=; b=Mu+8kLHvn78kOAjqoMKHiLyjUqY5ajgWzHnQcyaU5jvQH4Vn2pZVZuI+ktsl/JSa1M Q99WdG7ZZTYTgjyXRnmpdDBqDDCPxqWCaqCUmz05PBSdExIqAifZNxe87PWzRZ9eWUW4 xeg0XdM15gkLkfm/6xrjdMesoI0Uzkp/zqlQMz59N/VWz2KBnkwSyb3i79krH/BB2H2+ Gl10YVjdwUd+Q2oNQQgU91WWogWx1AGgc05gac2u43ThyWwPQ639TfTmhlUghF6vHGUh TP5C/LIECRMgAFmIdZHLxI4zP10y7UXoYU+hleqvyMVS9+eF2W1lxlwzYyHlZ8mUmnbF I72g== X-Gm-Message-State: AOAM533lJ3zWz7Gp3Pa0PIkTvv1axNI7NPzCkdB+9znHCaU4Tw52SH3w Zz1B9Cc6pys4BuuaYd4KjMBzH2MJrC21eUSy4hAjVP7HnZBiu0AnsmL/H+FWZRqDKS5nZBdECeh /Mw6g41D95yFuvXOUZiY8Z/kCJYxaJa/FdYQLYJ1mxJoHX/2J2hnGh8KCS58iImPPsWp50rE4 X-Received: by 2002:ac8:5e91:: with SMTP id r17mr691700qtx.48.1627494425309; Wed, 28 Jul 2021 10:47:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyND1Jwhl2Hra2xLnQeXZxikMT9yn61NF/kx7WmnyOvGGmEIjvCvMfp2oylr/EHBm7P4kjlmw== X-Received: by 2002:ac8:5e91:: with SMTP id r17mr691674qtx.48.1627494425028; Wed, 28 Jul 2021 10:47:05 -0700 (PDT) Received: from localhost (c-71-232-17-31.hsd1.ma.comcast.net. [71.232.17.31]) by smtp.gmail.com with ESMTPSA id b23sm310594qkl.113.2021.07.28.10.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 10:47:04 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v1] nis: Fix leak on realloc failure in nis_getnames Date: Wed, 28 Jul 2021 13:47:03 -0400 Message-ID: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/x-diff Content-Disposition: inline; filename=v1-0001-nis-Fix-leak-on-realloc-failure-in-nis_getnames.patch X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Robbie Harwood via Libc-alpha Reply-To: Robbie Harwood Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" >From 7aa0a9f879d5b2117beb06771bb4fdbaf25699a9 Mon Sep 17 00:00:00 2001 From: Robbie Harwood Date: Wed, 28 Jul 2021 12:54:44 -0400 Subject: [PATCH v1] nis: Fix leak on realloc failure in nis_getnames To: libc-alpha@sourceware.org Cc: kukuk@suse.de If pos >= count but realloc fails, tmp will not have been placed in getnames[pos] yet, and so will not be freed in free_null. Detected by Coverity. Also remove misleading comment from nis_getnames(), since it actually did properly release getnames when out of memory. --- nis/nis_subr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nis/nis_subr.c b/nis/nis_subr.c index dd0e30071d..6784fc353f 100644 --- a/nis/nis_subr.c +++ b/nis/nis_subr.c @@ -103,9 +103,6 @@ count_dots (const_nis_name str) return count; } -/* If we run out of memory, we don't give already allocated memory - free. The overhead for bringing getnames back in a safe state to - free it is to big. */ nis_name * nis_getnames (const_nis_name name) { @@ -271,7 +268,10 @@ nis_getnames (const_nis_name name) nis_name *newp = realloc (getnames, (count + 1) * sizeof (char *)); if (__glibc_unlikely (newp == NULL)) - goto free_null; + { + free (tmp); + goto free_null; + } getnames = newp; } getnames[pos] = tmp; -- 2.32.0