From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Boris Ostrovsky <boris.ostrovsky@oracle.com>,
ian.campbell@citrix.com, ian.jackson@eu.citrix.com,
jbeulich@suse.com, keir@xen.org, tim@xen.org
Cc: xen-devel@lists.xen.org
Subject: Re: [PATCH] vsprintf: Make sure argument to %*ph/%pv is valid
Date: Tue, 10 Feb 2015 21:49:32 +0000 [thread overview]
Message-ID: <54DA7CEC.9070308@citrix.com> (raw)
In-Reply-To: <1423604687-3586-1-git-send-email-boris.ostrovsky@oracle.com>
On 10/02/2015 21:44, Boris Ostrovsky wrote:
> If NULL pointer is passed for these specifiers then print '-'
> or 'd-v-'.
>
> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Instead of special casing each custom format, I would be tempted just to
put the switch() in an if(arg) conditional, and fall back to the regular
number for a NULL pointer, or go along the glibc route and print "(NULL)".
I presume you found this by falling over a NULL pointer while
debugging? I can't see a legitimate reason for formally supporting NULL
pointers in each context, but crashing is certainly better avoided.
~Andrew
> ---
> xen/common/vsprintf.c | 19 +++++++++++++++++++
> 1 files changed, 19 insertions(+), 0 deletions(-)
>
> diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c
> index 065cc42..84cfa85 100644
> --- a/xen/common/vsprintf.c
> +++ b/xen/common/vsprintf.c
> @@ -280,6 +280,13 @@ static char *pointer(char *str, char *end, const char **fmt_ptr,
> /* Consumed 'h' from the format string. */
> ++*fmt_ptr;
>
> + if ( hex_buffer == NULL )
> + {
> + if ( str < end )
> + *str++ = '-';
> + return str;
> + }
> +
> /* Bound user count from %* to between 0 and 64 bytes. */
> if ( field_width <= 0 )
> return str;
> @@ -338,6 +345,18 @@ static char *pointer(char *str, char *end, const char **fmt_ptr,
> ++*fmt_ptr;
> if ( str < end )
> *str = 'd';
> + if ( v == NULL )
> + {
> + /* If v is NULL then print 'd-v-' */
> + str++;
> + if ( str < end )
> + *str++ = '-';
> + if ( str < end )
> + *str++ = 'v';
> + if ( str < end )
> + *str++ = '-';
> + return str;
> + }
> str = number(str + 1, end, v->domain->domain_id, 10, -1, -1, 0);
> if ( str < end )
> *str = 'v';
next prev parent reply other threads:[~2015-02-10 21:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-10 21:44 [PATCH] vsprintf: Make sure argument to %*ph/%pv is valid Boris Ostrovsky
2015-02-10 21:49 ` Andrew Cooper [this message]
2015-02-10 21:55 ` Boris Ostrovsky
2015-02-11 8:27 ` Jan Beulich
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=54DA7CEC.9070308@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=keir@xen.org \
--cc=tim@xen.org \
--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.