]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
x86/mce/dev-mcelog: Fix -Wstringop-truncation warning about strncpy()
authorTony Luck <tony.luck@intel.com>
Wed, 27 May 2020 18:28:08 +0000 (11:28 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 24 Jun 2020 15:49:10 +0000 (17:49 +0200)
[ Upstream commit 7ccddc4613db446dc3cbb69a3763ba60ec651d13 ]

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>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200527182808.27737-1-tony.luck@intel.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/kernel/cpu/mce/dev-mcelog.c

index d089567a9ce82228cff67cb9ea151460651a31a9..bcb379b2fd42e530d6db9988cf89e4f60ef90259 100644 (file)
@@ -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);