From patchwork Tue Sep 25 08:13:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhi Li X-Patchwork-Id: 10613605 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 6918C6CB for ; Tue, 25 Sep 2018 08:13:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 573D829AFF for ; Tue, 25 Sep 2018 08:13:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 472D829B1D; Tue, 25 Sep 2018 08:13:36 +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 CEB9629AFF for ; Tue, 25 Sep 2018 08:13:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727308AbeIYOT4 (ORCPT ); Tue, 25 Sep 2018 10:19:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55462 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727114AbeIYOT4 (ORCPT ); Tue, 25 Sep 2018 10:19:56 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DEB79C015C37 for ; Tue, 25 Sep 2018 08:13:34 +0000 (UTC) Received: from localhost (dhcp-13-153.nay.redhat.com [10.66.13.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D5085D6A9; Tue, 25 Sep 2018 08:13:34 +0000 (UTC) From: Zhi Li To: linux-nfs@vger.kernel.org Cc: steved@redhat.com, Zhi Li Subject: [PATCH] getnetconfig.c: fix a BAD_FREE (CWE-763) Date: Tue, 25 Sep 2018 16:13:32 +0800 Message-Id: <1537863212-1389-1-git-send-email-yieli@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 25 Sep 2018 08:13:34 +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 --- https://bugzilla.redhat.com/show_bug.cgi?id=1631614 src/getnetconfig.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/getnetconfig.c b/src/getnetconfig.c index d67d97d..869556d 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,12 +701,12 @@ 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); @@ -714,8 +715,8 @@ struct netconfig *ncp; 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); }