linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] getnetconfig.c: fix a BAD_FREE (CWE-763)
@ 2018-09-25  8:13 Zhi Li
  2018-09-25 15:44 ` Steve Dickson
  0 siblings, 1 reply; 2+ messages in thread
From: Zhi Li @ 2018-09-25  8:13 UTC (permalink / raw)
  To: linux-nfs; +Cc: steved, Zhi Li

Signed-off-by: Zhi Li <yieli@redhat.com>
---

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] getnetconfig.c: fix a BAD_FREE (CWE-763)
  2018-09-25  8:13 [PATCH] getnetconfig.c: fix a BAD_FREE (CWE-763) Zhi Li
@ 2018-09-25 15:44 ` Steve Dickson
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Dickson @ 2018-09-25 15:44 UTC (permalink / raw)
  To: Zhi Li, linux-nfs



On 9/25/18 4:13 AM, Zhi Li wrote:
> Signed-off-by: Zhi Li <yieli@redhat.com>
> ---
> 
> 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);
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?

steved.


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-25 21:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-25  8:13 [PATCH] getnetconfig.c: fix a BAD_FREE (CWE-763) Zhi Li
2018-09-25 15:44 ` Steve Dickson

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).