mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RESEND] locking/lockdep: fix format-truncation compiler-warning
@ 2023-10-12 10:44 Lucy Mielke
  2023-10-12 18:43 ` [tip: locking/core] locking/lockdep: Fix string sizing bug that triggers a " tip-bot2 for Lucy Mielke
  0 siblings, 1 reply; 2+ messages in thread
From: Lucy Mielke @ 2023-10-12 10:44 UTC (permalink / raw)
  To: peterz, mingo, will, longman, boqun.feng; +Cc: linux-kernel

Compiler: gcc x86_64 v13.2.1
Config: allyesconfig, "treat warnings as errors" unset

This fixes the following compiler-warnings emitted by GCC:
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

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 buffer size of 22 is
needed here.

Signed-off-by: Lucy Mielke <lucymielke@icloud.com>
---
 kernel/locking/lockdep_proc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 15fdc7fa5c68..e2bfb1db589d 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -440,7 +440,7 @@ static void snprint_time(char *buf, size_t bufsiz, s64 nr)
 
 static void seq_time(struct seq_file *m, s64 time)
 {
-	char num[15];
+	char num[22];
 
 	snprint_time(num, sizeof(num), time);
 	seq_printf(m, " %14s", num);
-- 
2.41.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [tip: locking/core] locking/lockdep: Fix string sizing bug that triggers a format-truncation compiler-warning
  2023-10-12 10:44 [PATCH RESEND] locking/lockdep: fix format-truncation compiler-warning Lucy Mielke
@ 2023-10-12 18:43 ` tip-bot2 for Lucy Mielke
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Lucy Mielke @ 2023-10-12 18:43 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Lucy Mielke, Ingo Molnar, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     ac8b60be078abebc3ab8836f3f0ecac6980e0b4f
Gitweb:        https://git.kernel.org/tip/ac8b60be078abebc3ab8836f3f0ecac6980e0b4f
Author:        Lucy Mielke <lucymielke@icloud.com>
AuthorDate:    Thu, 12 Oct 2023 12:44:32 +02:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Thu, 12 Oct 2023 20:37:59 +02:00

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 <lucymielke@icloud.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/ZSfOEHRkZAWaQr3U@fedora.fritz.box
---
 kernel/locking/lockdep_proc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 15fdc7f..e2bfb1d 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -440,7 +440,7 @@ static void snprint_time(char *buf, size_t bufsiz, s64 nr)
 
 static void seq_time(struct seq_file *m, s64 time)
 {
-	char num[15];
+	char num[22];
 
 	snprint_time(num, sizeof(num), time);
 	seq_printf(m, " %14s", num);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-12 18:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-12 10:44 [PATCH RESEND] locking/lockdep: fix format-truncation compiler-warning Lucy Mielke
2023-10-12 18:43 ` [tip: locking/core] locking/lockdep: Fix string sizing bug that triggers a " tip-bot2 for Lucy Mielke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®