From: Linus Torvalds Date: Mon, 13 Jan 2025 16:23:28 +0000 (-0800) Subject: vsnprintf: fix the number base for non-numeric formats X-Git-Tag: v6.14-rc1~221^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ecdc475e0707c98c2a89da8d0024b3ea2924ef9b;p=thirdparty%2Fkernel%2Flinux.git vsnprintf: fix the number base for non-numeric formats 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 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 --- diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 4432b69a78be8..56fe963192926 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -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++;