From patchwork Wed Sep 26 03:25:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhi Li X-Patchwork-Id: 10615185 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 01A6613A4 for ; Wed, 26 Sep 2018 03:25:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E58812A97A for ; Wed, 26 Sep 2018 03:25:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9A252AC7C; Wed, 26 Sep 2018 03:25:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B7632A97A for ; Wed, 26 Sep 2018 03:25:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726520AbeIZJgk (ORCPT ); Wed, 26 Sep 2018 05:36:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58708 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726250AbeIZJgk (ORCPT ); Wed, 26 Sep 2018 05:36:40 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E8D03DE35 for ; Wed, 26 Sep 2018 03:25:55 +0000 (UTC) Received: from localhost (dhcp-13-153.nay.redhat.com [10.66.13.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id D23D36A6A3; Wed, 26 Sep 2018 03:25:54 +0000 (UTC) From: Zhi Li To: linux-nfs@vger.kernel.org Cc: steved@redhat.com, Zhi Li Subject: [PATCH-V2] [libtirpc] getnetconfig.c: fix a BAD_FREE (CWE-763) Date: Wed, 26 Sep 2018 11:25:51 +0800 Message-Id: <1537932352-19537-1-git-send-email-yieli@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 26 Sep 2018 03:25:55 +0000 (UTC) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Zhi Li --- From steved: Ok... I see why tmp original value needs to be maintained to do the free()... but I'm wondering why the freeing of p->nc_netid is needed... it appears to me it is part of tmp string... so when tmp is freed won't p->nc_netid be freed as well? Reply: Yes,you are right, p->nc_neti is a part of tmp string, so freeing tmp can make p->nc_neti be freed as well. p->nc_neti and tmp point to the same block of memory, so I only need to free p->nc_neti. I have update the issue. src/getnetconfig.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/getnetconfig.c b/src/getnetconfig.c index d67d97d..11b2449 100644 --- a/src/getnetconfig.c +++ b/src/getnetconfig.c @@ -710,7 +710,6 @@ struct netconfig *ncp; if (p->nc_lookups == NULL) { free(p->nc_netid); free(p); - free(tmp); return(NULL); } for (i=0; i < p->nc_nlookups; i++) {