All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vsprintf: make %pV handling compatible with kasprintf()
@ 2012-03-05 16:49 Jan Beulich
  2012-03-05 17:02 ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2012-03-05 16:49 UTC (permalink / raw)
  To: akpm, Linus Torvalds; +Cc: linux-kernel

kasprintf() (and potentially other functions that I didn't run across
so far) want to evaluate argument lists twice. Caring to do so for the
primary list is obviously their job, but they can't reasonably be
expected to check the format string for instances of %pV, which however
need special handling too: On architectures like x86-64 (as opposed to
e.g. ix86), using the same argument list twice doesn't produce the
expected results, as an internally managed cursor gets updated during
the first run.

Fix the problem by always acting on a copy of the original list when
handling %pV.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

---
 lib/vsprintf.c |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

--- 3.3-rc6/lib/vsprintf.c
+++ 3.3-rc6-kasprintf-pV/lib/vsprintf.c
@@ -891,9 +891,15 @@ char *pointer(const char *fmt, char *buf
 	case 'U':
 		return uuid_string(buf, end, ptr, spec, fmt);
 	case 'V':
-		return buf + vsnprintf(buf, end > buf ? end - buf : 0,
-				       ((struct va_format *)ptr)->fmt,
-				       *(((struct va_format *)ptr)->va));
+		{
+			va_list va;
+
+			va_copy(va, *((struct va_format *)ptr)->va);
+			buf += vsnprintf(buf, end > buf ? end - buf : 0,
+					 ((struct va_format *)ptr)->fmt, va);
+			va_end(va);
+			return buf;
+		}
 	case 'K':
 		/*
 		 * %pK cannot be used in IRQ context because its test




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

* Re: [PATCH] vsprintf: make %pV handling compatible with kasprintf()
  2012-03-05 16:49 [PATCH] vsprintf: make %pV handling compatible with kasprintf() Jan Beulich
@ 2012-03-05 17:02 ` Joe Perches
  2012-03-06  7:50   ` Jan Beulich
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2012-03-05 17:02 UTC (permalink / raw)
  To: Jan Beulich; +Cc: akpm, Linus Torvalds, linux-kernel

On Mon, 2012-03-05 at 16:49 +0000, Jan Beulich wrote:
> kasprintf() (and potentially other functions that I didn't run across
> so far) want to evaluate argument lists twice. Caring to do so for the
> primary list is obviously their job, but they can't reasonably be
> expected to check the format string for instances of %pV, which however
> need special handling too: On architectures like x86-64 (as opposed to
> e.g. ix86), using the same argument list twice doesn't produce the
> expected results, as an internally managed cursor gets updated during
> the first run.
> 
> Fix the problem by always acting on a copy of the original list when
> handling %pV.

Wouldn't stable need this too?



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

* Re: [PATCH] vsprintf: make %pV handling compatible with kasprintf()
  2012-03-05 17:02 ` Joe Perches
@ 2012-03-06  7:50   ` Jan Beulich
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2012-03-06  7:50 UTC (permalink / raw)
  To: Joe Perches; +Cc: akpm, Linus Torvalds, linux-kernel

>>> On 05.03.12 at 18:02, Joe Perches <joe@perches.com> wrote:
> On Mon, 2012-03-05 at 16:49 +0000, Jan Beulich wrote:
>> kasprintf() (and potentially other functions that I didn't run across
>> so far) want to evaluate argument lists twice. Caring to do so for the
>> primary list is obviously their job, but they can't reasonably be
>> expected to check the format string for instances of %pV, which however
>> need special handling too: On architectures like x86-64 (as opposed to
>> e.g. ix86), using the same argument list twice doesn't produce the
>> expected results, as an internally managed cursor gets updated during
>> the first run.
>> 
>> Fix the problem by always acting on a copy of the original list when
>> handling %pV.
> 
> Wouldn't stable need this too?

Possibly, but I'm not certain - this is more of a latent bug that I ran
into with some not yet submitted Xen code. And I'm not sure
whether latent bugs qualify for stable...

Jan


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

end of thread, other threads:[~2012-03-06  7:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-05 16:49 [PATCH] vsprintf: make %pV handling compatible with kasprintf() Jan Beulich
2012-03-05 17:02 ` Joe Perches
2012-03-06  7:50   ` Jan Beulich

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.