[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1354813775-32451-1-git-send-email-s.munaut@whatever-company.com>
Date: Thu, 6 Dec 2012 18:09:35 +0100
From: Sylvain Munaut <s.munaut@...tever-company.com>
To: torvalds@...ux-foundation.org
Cc: linux-kernel@...r.kernel.org,
Sylvain Munaut <s.munaut@...tever-company.com>,
Kay Sievers <kay@...y.org>, stable@...nel.org
Subject: [PATCH] printk: Fix print_time length computation when no buffer is given
The "%5lu" part of the sprintf only guarantees a minimum length,
not a maximum one. This patch should make it correct for any
possible timestamp.
This problem dates back from the printk conversion to records AFAICT.
I've tested this locally both by verifying 'dmesg' no longer
segfaulted and also by checking that before this patch the
buffer was overrun by exactly the number of char corresponding to
extra digits in the timestamps.
Cc: Kay Sievers <kay@...y.org>
Cc: stable@...nel.org
Signed-off-by: Sylvain Munaut <s.munaut@...tever-company.com>
---
kernel/printk.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/kernel/printk.c b/kernel/printk.c
index 66a2ea3..2ceceea 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -847,8 +847,17 @@ static size_t print_time(u64 ts, char *buf)
if (!printk_time)
return 0;
- if (!buf)
- return 15;
+ if (!buf) {
+ size_t len = 15;
+ u64 ts_limit = (u64)100000 * (u64)1000000000;
+
+ while ((ts > ts_limit) && (len < 21)) {
+ len++;
+ ts_limit = 10 * ts_limit;
+ }
+
+ return len;
+ }
rem_nsec = do_div(ts, 1000000000);
return sprintf(buf, "[%5lu.%06lu] ",
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists