summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2025-11-10 14:21:18 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-12-18 14:02:58 +0100
commite0a7eab9165a6a0dcaf1306c3f1aa6a151e4aa95 (patch)
tree1f8cc9dc6c7d963ba9f71e9a8e6a0f8c9176ea55 /lib
parent8cacdb0f0bca048bcffd1b8c48a3daa40dcae3a6 (diff)
downloadlinux-e0a7eab9165a6a0dcaf1306c3f1aa6a151e4aa95.tar.gz
linux-e0a7eab9165a6a0dcaf1306c3f1aa6a151e4aa95.tar.bz2
linux-e0a7eab9165a6a0dcaf1306c3f1aa6a151e4aa95.zip
lib/vsprintf: Check pointer before dereferencing in time_and_date()
[ Upstream commit 372a12bd5df0199aa234eaf8ef31ed7ecd61d40f ] The pointer may be invalid when gets to the printf(). In particular the time_and_date() dereferencing it in some cases without checking. Move the check from rtc_str() to time_and_date() to cover all cases. Fixes: 7daac5b2fdf8 ("lib/vsprintf: Print time64_t in human readable format") Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Petr Mladek <pmladek@suse.com> Link: https://patch.msgid.link/20251110132118.4113976-1-andriy.shevchenko@linux.intel.com Signed-off-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/vsprintf.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index eb0cb11d0d12..a356965c1d73 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1928,9 +1928,6 @@ char *rtc_str(char *buf, char *end, const struct rtc_time *tm,
bool found = true;
int count = 2;
- if (check_pointer(&buf, end, tm, spec))
- return buf;
-
switch (fmt[count]) {
case 'd':
have_t = false;
@@ -1996,6 +1993,9 @@ static noinline_for_stack
char *time_and_date(char *buf, char *end, void *ptr, struct printf_spec spec,
const char *fmt)
{
+ if (check_pointer(&buf, end, ptr, spec))
+ return buf;
+
switch (fmt[1]) {
case 'R':
return rtc_str(buf, end, (const struct rtc_time *)ptr, spec, fmt);