]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
vsnprintf: fix the number base for non-numeric formats
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 13 Jan 2025 16:23:28 +0000 (08:23 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 13 Jan 2025 16:23:28 +0000 (08:23 -0800)
Commit 8d4826cc8a8a ("vsnprintf: collapse the number format state into
one single state") changed the format specification decoding to be a bit
more straightforward but in the process ended up also resetting the
number base to zero for formats that aren't clearly numerical.

Now, the number base obviously doesn't matter for something like '%s',
so this wasn't all that obvious.  But some of our specialized pointer
extension formatting (ie, things like "print out IPv6 address") did up
depending on the default base-10 setting, and when they then tried to
print out numbers in "base zero", things didn't work out so well.

Most pointer formatting (including things like the default raw hex value
conversion) didn't have this issue, because they used helpers that
explicitly set the base.

Reported-and-tested-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202501131352.e226f995-lkp@intel.com
Fixes: 8d4826cc8a8a ("vsnprintf: collapse the number format state into one single state")
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/vsprintf.c

index 4432b69a78be884fbde9d792003fa8c788213257..56fe96319292674c9f79559cf78dd0d99d1a1f06 100644 (file)
@@ -2682,7 +2682,8 @@ qualifier:
                p = lookup_state + *fmt.str;
        }
        if (p->state) {
-               spec->base = p->base;
+               if (p->base)
+                       spec->base = p->base;
                spec->flags |= p->flags_or_double_size;
                fmt.state = p->state;
                fmt.str++;