All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Ian Campbell <Ian.Campbell@citrix.com>,
	Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH for-4.6] tools/xenstore: Correct use of va_end() after va_copy()
Date: Fri, 7 Aug 2015 15:22:03 +0100	[thread overview]
Message-ID: <20150807142203.GA29712@zion.uk.xensource.com> (raw)
In-Reply-To: <1438955519-7071-1-git-send-email-andrew.cooper3@citrix.com>

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

  reply	other threads:[~2015-08-07 14:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2015-08-13  9:45 ` Wei Liu
2015-08-13 10:31   ` Ian Campbell

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=20150807142203.GA29712@zion.uk.xensource.com \
    --to=wei.liu2@citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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 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.