Skip to content

Commit ac8b60b

Browse files
el-puerroIngo Molnar
authored and
Ingo Molnar
committed
locking/lockdep: Fix string sizing bug that triggers a format-truncation compiler-warning
On an allyesconfig, with "treat warnings as errors" unset, GCC emits these warnings: kernel/locking/lockdep_proc.c:438:32: Warning: Format specifier '%lld' may be truncated when writing 1 to 17 bytes into a region of size 15 [-Wformat-truncation=] kernel/locking/lockdep_proc.c:438:31: Note: Format directive argument is in the range [-9223372036854775, 9223372036854775] kernel/locking/lockdep_proc.c:438:9: Note: 'snprintf' has output between 5 and 22 bytes into a target of size 15 In seq_time(), the longest s64 is "-9223372036854775808"-ish, which converted to the fixed-point float format is "-9223372036854775.80": 21 bytes, plus termination is another byte: 22. Therefore, a larger buffer size of 22 is needed here - not 15. The code was safe due to the snprintf(). Fix it. Signed-off-by: Lucy Mielke <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e6115c6 commit ac8b60b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/locking/lockdep_proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ static void snprint_time(char *buf, size_t bufsiz, s64 nr)
440440

441441
static void seq_time(struct seq_file *m, s64 time)
442442
{
443-
char num[15];
443+
char num[22];
444444

445445
snprint_time(num, sizeof(num), time);
446446
seq_printf(m, " %14s", num);

0 commit comments

Comments
 (0)