linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steve Dickson <SteveD@RedHat.com>
To: Zhi Li <yieli@redhat.com>, linux-nfs@vger.kernel.org
Subject: Re: [PATCH-V2] [nfs/nfs-utils/libtirpc] src/getnetconfig.c: fix a BAD_FREE (CWE-763)
Date: Wed, 26 Sep 2018 14:08:36 -0400	[thread overview]
Message-ID: <df0f1cea-f425-b3f5-bc10-a698612feced@RedHat.com> (raw)
In-Reply-To: <1537932352-19537-2-git-send-email-yieli@redhat.com>



On 9/25/18 11:25 PM, Zhi Li wrote:
> Signed-off-by: Zhi Li <yieli@redhat.com>
> ---
> 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(-)
Committed... 

steved.

> 
> 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);
>  }
> 

      reply	other threads:[~2018-09-27  0:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-26  3:25 [PATCH-V2] [libtirpc] getnetconfig.c: fix a BAD_FREE (CWE-763) Zhi Li
2018-09-26  3:25 ` [PATCH-V2] [nfs/nfs-utils/libtirpc] src/getnetconfig.c: " Zhi Li
2018-09-26 18:08   ` Steve Dickson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=df0f1cea-f425-b3f5-bc10-a698612feced@RedHat.com \
    --to=steved@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=yieli@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).