From: "Jan Beulich" Subject: Re: [PATCH v3] vsprintf: Make sure argument to %pX specifier is valid Date: Wed, 18 Feb 2015 16:19:11 +0000 Message-ID: <54E4C98F02000078000612B0@mail.emea.novell.com> References: <1424273966-3566-1-git-send-email-boris.ostrovsky@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1424273966-3566-1-git-send-email-boris.ostrovsky@oracle.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Boris Ostrovsky Cc: keir@xen.org, tim@xen.org, ian.jackson@eu.citrix.com, ian.campbell@citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org >>> On 18.02.15 at 16:39, wrote: > --- a/xen/common/vsprintf.c > +++ b/xen/common/vsprintf.c > @@ -269,7 +269,28 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, > { > const char *fmt = *fmt_ptr, *s; > > - /* Custom %p suffixes. See XEN_ROOT/docs/misc/printk-formats.txt */ > + /* > + * For custom %p suffixes (see XEN_ROOT/docs/misc/printk-formats.txt) > + * if arg pointer is bogus then print pointer value in parentheses. > + */ > + if ( (unsigned long)arg < HYPERVISOR_VIRT_START ) > + { > + switch (fmt[1]) > + { > + case 'h': > + case 's': > + case 'S': > + case 'v': > + ++*fmt_ptr; > + if ( str < end ) > + *str++ = '('; > + str = number(str, end, (unsigned long)arg, 16, -1, -1, ZEROPAD); > + if ( str < end ) > + *str++ = ')'; You should take existing code as reference when adding to it: Both increments above need to happen unconditionally. Jan