All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/mce/dev-mcelog: Fix "make W=1" warning about strncpy
@ 2020-05-27 18:28 Tony Luck
  2020-05-27 19:46 ` [tip: ras/core] x86/mce/dev-mcelog: Fix -Wstringop-truncation warning about strncpy() tip-bot2 for Tony Luck
  0 siblings, 1 reply; 2+ messages in thread
From: Tony Luck @ 2020-05-27 18:28 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: Tony Luck, kbuild test robot, x86, linux-kernel

The kbuild test robot reported this warning:

arch/x86/kernel/cpu/mce/dev-mcelog.c: In function 'dev_mcelog_init_device':
arch/x86/kernel/cpu/mce/dev-mcelog.c:346:2: warning: 'strncpy' output truncated before terminating nul copying 12 bytes from a string of the same length [-Wstringop-truncation]

This is accurate, but I don't care that the trailing NUL character isn't copied.
The string being copied is just a magic number signature so that crash dump
tools can be sure they are decoding the right blob of memory.

Change to use memcpy() instead of strncpy()

Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
---
 arch/x86/kernel/cpu/mce/dev-mcelog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c
index d089567a9ce8..bcb379b2fd42 100644
--- a/arch/x86/kernel/cpu/mce/dev-mcelog.c
+++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c
@@ -343,7 +343,7 @@ static __init int dev_mcelog_init_device(void)
 	if (!mcelog)
 		return -ENOMEM;
 
-	strncpy(mcelog->signature, MCE_LOG_SIGNATURE, sizeof(mcelog->signature));
+	memcpy(mcelog->signature, MCE_LOG_SIGNATURE, sizeof(mcelog->signature));
 	mcelog->len = mce_log_len;
 	mcelog->recordlen = sizeof(struct mce);
 
-- 
2.21.1


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

* [tip: ras/core] x86/mce/dev-mcelog: Fix -Wstringop-truncation warning about strncpy()
  2020-05-27 18:28 [PATCH] x86/mce/dev-mcelog: Fix "make W=1" warning about strncpy Tony Luck
@ 2020-05-27 19:46 ` tip-bot2 for Tony Luck
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Tony Luck @ 2020-05-27 19:46 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: kbuild test robot, Tony Luck, Borislav Petkov, x86, LKML

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

Commit-ID:     45811ba140593e288a288c2a2e45d25f38d20d73
Gitweb:        https://git.kernel.org/tip/45811ba140593e288a288c2a2e45d25f38d20d73
Author:        Tony Luck <tony.luck@intel.com>
AuthorDate:    Wed, 27 May 2020 11:28:08 -07:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Wed, 27 May 2020 21:19:38 +02:00

x86/mce/dev-mcelog: Fix -Wstringop-truncation warning about strncpy()

The kbuild test robot reported this warning:

  arch/x86/kernel/cpu/mce/dev-mcelog.c: In function 'dev_mcelog_init_device':
  arch/x86/kernel/cpu/mce/dev-mcelog.c:346:2: warning: 'strncpy' output \
    truncated before terminating nul copying 12 bytes from a string of the \
    same length [-Wstringop-truncation]

This is accurate, but I don't care that the trailing NUL character isn't
copied. The string being copied is just a magic number signature so that
crash dump tools can be sure they are decoding the right blob of memory.

Use memcpy() instead of strncpy().

Fixes: d8ecca4043f2 ("x86/mce/dev-mcelog: Dynamically allocate space for machine check records")
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20200527182808.27737-1-tony.luck@intel.com
---
 arch/x86/kernel/cpu/mce/dev-mcelog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c
index a4fd528..43c4660 100644
--- a/arch/x86/kernel/cpu/mce/dev-mcelog.c
+++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c
@@ -349,7 +349,7 @@ static __init int dev_mcelog_init_device(void)
 	if (!mcelog)
 		return -ENOMEM;
 
-	strncpy(mcelog->signature, MCE_LOG_SIGNATURE, sizeof(mcelog->signature));
+	memcpy(mcelog->signature, MCE_LOG_SIGNATURE, sizeof(mcelog->signature));
 	mcelog->len = mce_log_len;
 	mcelog->recordlen = sizeof(struct mce);
 

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

end of thread, other threads:[~2020-05-27 19:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-27 18:28 [PATCH] x86/mce/dev-mcelog: Fix "make W=1" warning about strncpy Tony Luck
2020-05-27 19:46 ` [tip: ras/core] x86/mce/dev-mcelog: Fix -Wstringop-truncation warning about strncpy() tip-bot2 for Tony Luck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.