From patchwork Wed Sep 26 03:25:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhi Li X-Patchwork-Id: 10615187 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 633E213A4 for ; Wed, 26 Sep 2018 03:26:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 550892A97A for ; Wed, 26 Sep 2018 03:26:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48CAC2AC7C; Wed, 26 Sep 2018 03:26:00 +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 E37872A97A for ; Wed, 26 Sep 2018 03:25:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726534AbeIZJgo (ORCPT ); Wed, 26 Sep 2018 05:36:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52696 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726250AbeIZJgo (ORCPT ); Wed, 26 Sep 2018 05:36:44 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 307F9285B0 for ; Wed, 26 Sep 2018 03:25:59 +0000 (UTC) Received: from localhost (dhcp-13-153.nay.redhat.com [10.66.13.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92E241A920; Wed, 26 Sep 2018 03:25:58 +0000 (UTC) From: Zhi Li To: linux-nfs@vger.kernel.org Cc: steved@redhat.com, Zhi Li Subject: [PATCH-V2] [nfs/nfs-utils/libtirpc] src/getnetconfig.c: fix a BAD_FREE (CWE-763) Date: Wed, 26 Sep 2018 11:25:52 +0800 Message-Id: <1537932352-19537-2-git-send-email-yieli@redhat.com> In-Reply-To: <1537932352-19537-1-git-send-email-yieli@redhat.com> References: <1537932352-19537-1-git-send-email-yieli@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 26 Sep 2018 03:25:59 +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. I have update the issue. src/getnetconfig.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/getnetconfig.c b/src/getnetconfig.c index d67d97d..cfd33c2 100644 --- a/src/getnetconfig.c +++ b/src/getnetconfig.c @@ -681,6 +681,7 @@ struct netconfig *ncp; { struct netconfig *p; char *tmp; + char *t; u_int i; if ((tmp=malloc(MAXNETCONFIGLINE)) == NULL) @@ -700,22 +701,21 @@ struct netconfig *ncp; */ *p = *ncp; p->nc_netid = (char *)strcpy(tmp,ncp->nc_netid); - tmp = strchr(tmp, 0) + 1; - p->nc_protofmly = (char *)strcpy(tmp,ncp->nc_protofmly); - tmp = strchr(tmp, 0) + 1; - p->nc_proto = (char *)strcpy(tmp,ncp->nc_proto); - tmp = strchr(tmp, 0) + 1; - p->nc_device = (char *)strcpy(tmp,ncp->nc_device); + t = strchr(tmp, 0) + 1; + p->nc_protofmly = (char *)strcpy(t,ncp->nc_protofmly); + t = strchr(t, 0) + 1; + p->nc_proto = (char *)strcpy(t,ncp->nc_proto); + t = strchr(t, 0) + 1; + p->nc_device = (char *)strcpy(t,ncp->nc_device); p->nc_lookups = (char **)malloc((size_t)(p->nc_nlookups+1) * sizeof(char *)); if (p->nc_lookups == NULL) { - free(p->nc_netid); free(p); free(tmp); return(NULL); } for (i=0; i < p->nc_nlookups; i++) { - tmp = strchr(tmp, 0) + 1; - p->nc_lookups[i] = (char *)strcpy(tmp,ncp->nc_lookups[i]); + t = strchr(t, 0) + 1; + p->nc_lookups[i] = (char *)strcpy(t,ncp->nc_lookups[i]); } return(p); }