From patchwork Wed Jul 28 17:47:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robbie Harwood X-Patchwork-Id: 44503 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08FF8399E034 for ; Wed, 28 Jul 2021 17:47:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08FF8399E034 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1627494466; bh=qVZtlBjxtJPQQ9cJaRATG9Xd5AZyIgMXFj7UlAUPJs4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=rfrslJCWa/99RjNNwFp1HNveuyrHWKBlTKKLLr5w/+kY/JaTdjlhiC1mhxKkr1oaj bg1YydFIr8JvDiod9wwoVpzsw2QHUDTl6coCyx+16u2wlEdKNw8u4+pczMJhAUC/UI xzpG2iZiYsyxn9K5e52RpMnpPDmdy70UhhgaouVk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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-Disposition: inline; filename=v1-0001-nis-Fix-leak-on-realloc-failure-in-nis_getnames.patch X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-Patchwork-Original-From: Robbie Harwood via Libc-alpha From: Robbie Harwood Reply-To: Robbie Harwood Errors-To: libc-alpha-bounces+patchwork=sourceware.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