]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib/vsprintf: Check pointer before dereferencing in time_and_date()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 10 Nov 2025 13:21:18 +0000 (14:21 +0100)
committerPetr Mladek <pmladek@suse.com>
Wed, 12 Nov 2025 10:36:20 +0000 (11:36 +0100)
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>
lib/vsprintf.c

index e49f350ee549de9b06ac21c364279814d52d26c1..3f99834fd788fd25408cc66a193d2186611848d9 100644 (file)
@@ -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);