lib/vsprintf: Check pointer before dereferencing in time_and_date()
Subsystems (2)
Andy Shevchenko
reviewerPATCH 1/1 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.
--- lib/vsprintf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/vsprintf.c +3 -3
@@ -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_stackchar *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);
Signature · 1 line
2.50.1
Quoted 7 lines · Andy Shevchenko
The pointer may be invalid when gets to the
printf(). In particular thetime_and_date()dereferencing it in some cases without checking.Move the check from
rtc_str()totime_and_date()to cover all cases.Fixes 7daac5b2fdf8 ("lib/vsprintf: Print time64_t in human readable format")Signed-off-by Andy Shevchenko <[email protected]>
Great catch!
Best Regards,
Petr
Petr Mladek
maintainerQuoted 7 lines · Andy Shevchenko
The pointer may be invalid when gets to the
printf(). In particular thetime_and_date()dereferencing it in some cases without checking.Move the check from
rtc_str()totime_and_date()to cover all cases.Fixes 7daac5b2fdf8 ("lib/vsprintf: Print time64_t in human readable format")Signed-off-by Andy Shevchenko <[email protected]>
JFYI, the patch has been comitted into printk/linux.git, branch for-6.19.
Best Regards,
Petr