Skip to content

Commit 372a12b

Browse files
andy-shevpmladek
authored andcommitted
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: 7daac5b ("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>
1 parent 394aa57 commit 372a12b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lib/vsprintf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,9 +1928,6 @@ char *rtc_str(char *buf, char *end, const struct rtc_time *tm,
19281928
bool found = true;
19291929
int count = 2;
19301930

1931-
if (check_pointer(&buf, end, tm, spec))
1932-
return buf;
1933-
19341931
switch (fmt[count]) {
19351932
case 'd':
19361933
have_t = false;
@@ -1996,6 +1993,9 @@ static noinline_for_stack
19961993
char *time_and_date(char *buf, char *end, void *ptr, struct printf_spec spec,
19971994
const char *fmt)
19981995
{
1996+
if (check_pointer(&buf, end, ptr, spec))
1997+
return buf;
1998+
19991999
switch (fmt[1]) {
20002000
case 'R':
20012001
return rtc_str(buf, end, (const struct rtc_time *)ptr, spec, fmt);

0 commit comments

Comments
 (0)