All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-4.6] tools/xenstore: Correct use of va_end() after va_copy()
@ 2015-08-07 13:51 Andrew Cooper
  2015-08-07 14:22 ` Wei Liu
  2015-08-13  9:45 ` Wei Liu
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Cooper @ 2015-08-07 13:51 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Ian Jackson, Ian Campbell, Wei Liu

C requires that every use of va_copy() is matched with a va_end() call.

This is especially important for x86_64 as va_{start,copy}() may need to
allocate memory to generate a va_list containing parameters which were
previously in registers.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
---
 tools/xenstore/talloc.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/xenstore/talloc.c b/tools/xenstore/talloc.c
index 54dbd02..d7edcf3 100644
--- a/tools/xenstore/talloc.c
+++ b/tools/xenstore/talloc.c
@@ -1101,13 +1101,16 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
 
 	/* this call looks strange, but it makes it work on older solaris boxes */
 	if ((len = vsnprintf(&c, 1, fmt, ap2)) < 0) {
+		va_end(ap2);
 		return NULL;
 	}
+	va_end(ap2);
 
 	ret = _talloc(t, len+1);
 	if (ret) {
 		VA_COPY(ap2, ap);
 		vsnprintf(ret, len+1, fmt, ap2);
+		va_end(ap2);
 		talloc_set_name_const(ret, ret);
 	}
 
@@ -1161,8 +1164,10 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
 		 * the original string. Most current callers of this 
 		 * function expect it to never return NULL.
 		 */
+		va_end(ap2);
 		return s;
 	}
+	va_end(ap2);
 
 	s = talloc_realloc(NULL, s, char, s_len + len+1);
 	if (!s) return NULL;
@@ -1170,6 +1175,7 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
 	VA_COPY(ap2, ap);
 
 	vsnprintf(s+s_len, len+1, fmt, ap2);
+	va_end(ap2);
 	talloc_set_name_const(s, s);
 
 	return s;
-- 
1.7.10.4

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

* Re: [PATCH for-4.6] tools/xenstore: Correct use of va_end() after va_copy()
  2015-08-07 13:51 [PATCH for-4.6] tools/xenstore: Correct use of va_end() after va_copy() Andrew Cooper
@ 2015-08-07 14:22 ` Wei Liu
  2015-08-13  9:45 ` Wei Liu
  1 sibling, 0 replies; 4+ messages in thread
From: Wei Liu @ 2015-08-07 14:22 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Wei Liu, Ian Jackson, Ian Campbell, Xen-devel

On Fri, Aug 07, 2015 at 02:51:59PM +0100, Andrew Cooper wrote:
> C requires that every use of va_copy() is matched with a va_end() call.
> 
> This is especially important for x86_64 as va_{start,copy}() may need to
> allocate memory to generate a va_list containing parameters which were
> previously in registers.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Wei Liu <wei.liu2@citrix.com>

This is a candidate for backport.

> ---
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
> ---
>  tools/xenstore/talloc.c |    6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tools/xenstore/talloc.c b/tools/xenstore/talloc.c
> index 54dbd02..d7edcf3 100644
> --- a/tools/xenstore/talloc.c
> +++ b/tools/xenstore/talloc.c
> @@ -1101,13 +1101,16 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
>  
>  	/* this call looks strange, but it makes it work on older solaris boxes */
>  	if ((len = vsnprintf(&c, 1, fmt, ap2)) < 0) {
> +		va_end(ap2);
>  		return NULL;
>  	}
> +	va_end(ap2);
>  
>  	ret = _talloc(t, len+1);
>  	if (ret) {
>  		VA_COPY(ap2, ap);
>  		vsnprintf(ret, len+1, fmt, ap2);
> +		va_end(ap2);
>  		talloc_set_name_const(ret, ret);
>  	}
>  
> @@ -1161,8 +1164,10 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
>  		 * the original string. Most current callers of this 
>  		 * function expect it to never return NULL.
>  		 */
> +		va_end(ap2);
>  		return s;
>  	}
> +	va_end(ap2);
>  
>  	s = talloc_realloc(NULL, s, char, s_len + len+1);
>  	if (!s) return NULL;
> @@ -1170,6 +1175,7 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
>  	VA_COPY(ap2, ap);
>  
>  	vsnprintf(s+s_len, len+1, fmt, ap2);
> +	va_end(ap2);
>  	talloc_set_name_const(s, s);
>  
>  	return s;
> -- 
> 1.7.10.4

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

* Re: [PATCH for-4.6] tools/xenstore: Correct use of va_end() after va_copy()
  2015-08-07 13:51 [PATCH for-4.6] tools/xenstore: Correct use of va_end() after va_copy() Andrew Cooper
  2015-08-07 14:22 ` Wei Liu
@ 2015-08-13  9:45 ` Wei Liu
  2015-08-13 10:31   ` Ian Campbell
  1 sibling, 1 reply; 4+ messages in thread
From: Wei Liu @ 2015-08-13  9:45 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Wei Liu, Ian Jackson, Ian Campbell, Xen-devel

On Fri, Aug 07, 2015 at 02:51:59PM +0100, Andrew Cooper wrote:
> C requires that every use of va_copy() is matched with a va_end() call.
> 
> This is especially important for x86_64 as va_{start,copy}() may need to
> allocate memory to generate a va_list containing parameters which were
> previously in registers.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Release-acked-by: Wei Liu <wei.liu2@citrix.com>

> ---
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
> ---
>  tools/xenstore/talloc.c |    6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tools/xenstore/talloc.c b/tools/xenstore/talloc.c
> index 54dbd02..d7edcf3 100644
> --- a/tools/xenstore/talloc.c
> +++ b/tools/xenstore/talloc.c
> @@ -1101,13 +1101,16 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
>  
>  	/* this call looks strange, but it makes it work on older solaris boxes */
>  	if ((len = vsnprintf(&c, 1, fmt, ap2)) < 0) {
> +		va_end(ap2);
>  		return NULL;
>  	}
> +	va_end(ap2);
>  
>  	ret = _talloc(t, len+1);
>  	if (ret) {
>  		VA_COPY(ap2, ap);
>  		vsnprintf(ret, len+1, fmt, ap2);
> +		va_end(ap2);
>  		talloc_set_name_const(ret, ret);
>  	}
>  
> @@ -1161,8 +1164,10 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
>  		 * the original string. Most current callers of this 
>  		 * function expect it to never return NULL.
>  		 */
> +		va_end(ap2);
>  		return s;
>  	}
> +	va_end(ap2);
>  
>  	s = talloc_realloc(NULL, s, char, s_len + len+1);
>  	if (!s) return NULL;
> @@ -1170,6 +1175,7 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
>  	VA_COPY(ap2, ap);
>  
>  	vsnprintf(s+s_len, len+1, fmt, ap2);
> +	va_end(ap2);
>  	talloc_set_name_const(s, s);
>  
>  	return s;
> -- 
> 1.7.10.4

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

* Re: [PATCH for-4.6] tools/xenstore: Correct use of va_end() after va_copy()
  2015-08-13  9:45 ` Wei Liu
@ 2015-08-13 10:31   ` Ian Campbell
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Campbell @ 2015-08-13 10:31 UTC (permalink / raw)
  To: Wei Liu, Andrew Cooper; +Cc: Ian Jackson, Xen-devel

On Thu, 2015-08-13 at 10:45 +0100, Wei Liu wrote:
> On Fri, Aug 07, 2015 at 02:51:59PM +0100, Andrew Cooper wrote:
> > C requires that every use of va_copy() is matched with a va_end() call.
> > 
> > This is especially important for x86_64 as va_{start,copy}() may need 
> > to
> > allocate memory to generate a va_list containing parameters which were
> > previously in registers.
> > 
> > Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> 
> Release-acked-by: Wei Liu <wei.liu2@citrix.com>

Applied, thanks.

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

end of thread, other threads:[~2015-08-13 10:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-07 13:51 [PATCH for-4.6] tools/xenstore: Correct use of va_end() after va_copy() Andrew Cooper
2015-08-07 14:22 ` Wei Liu
2015-08-13  9:45 ` Wei Liu
2015-08-13 10:31   ` Ian Campbell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.