Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/vsprintf: Check pointer before dereferencing in time_and_date()

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>

authored by

Andy Shevchenko and committed by
Petr Mladek
372a12bd 394aa576

+3 -3
+3 -3
lib/vsprintf.c
··· 1928 1928 bool found = true; 1929 1929 int count = 2; 1930 1930 1931 - if (check_pointer(&buf, end, tm, spec)) 1932 - return buf; 1933 - 1934 1931 switch (fmt[count]) { 1935 1932 case 'd': 1936 1933 have_t = false; ··· 1993 1996 char *time_and_date(char *buf, char *end, void *ptr, struct printf_spec spec, 1994 1997 const char *fmt) 1995 1998 { 1999 + if (check_pointer(&buf, end, ptr, spec)) 2000 + return buf; 2001 + 1996 2002 switch (fmt[1]) { 1997 2003 case 'R': 1998 2004 return rtc_str(buf, end, (const struct rtc_time *)ptr, spec, fmt);