Commit c9599881 authored by Christophe Leroy's avatar Christophe Leroy Committed by Michael Ellerman

powerpc/64: Fix strncpy() related build failures with GCC 8.1

GCC 8.1 warns about possible string truncation:

  arch/powerpc/kernel/nvram_64.c:1042:2: error: 'strncpy' specified
  bound 12 equals destination size [-Werror=stringop-truncation]
    strncpy(new_part->header.name, name, 12);

  arch/powerpc/platforms/ps3/repository.c:106:2: error: 'strncpy'
  output truncated before terminating nul copying 8 bytes from a
  string of the same length [-Werror=stringop-truncation]
    strncpy((char *)&n, text, 8);

Fix it by using memcpy(). To make that safe we need to ensure the
destination is pre-zeroed. Use kzalloc() in the nvram code and
initialise the u64 to zero in the ps3 code.
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
[mpe: Use kzalloc() in the nvram code, flesh out change log]
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 2135a6ec
...@@ -1030,7 +1030,7 @@ loff_t __init nvram_create_partition(const char *name, int sig, ...@@ -1030,7 +1030,7 @@ loff_t __init nvram_create_partition(const char *name, int sig,
return -ENOSPC; return -ENOSPC;
/* Create our OS partition */ /* Create our OS partition */
new_part = kmalloc(sizeof(*new_part), GFP_KERNEL); new_part = kzalloc(sizeof(*new_part), GFP_KERNEL);
if (!new_part) { if (!new_part) {
pr_err("%s: kmalloc failed\n", __func__); pr_err("%s: kmalloc failed\n", __func__);
return -ENOMEM; return -ENOMEM;
...@@ -1039,7 +1039,7 @@ loff_t __init nvram_create_partition(const char *name, int sig, ...@@ -1039,7 +1039,7 @@ loff_t __init nvram_create_partition(const char *name, int sig,
new_part->index = free_part->index; new_part->index = free_part->index;
new_part->header.signature = sig; new_part->header.signature = sig;
new_part->header.length = size; new_part->header.length = size;
strncpy(new_part->header.name, name, 12); memcpy(new_part->header.name, name, strnlen(name, sizeof(new_part->header.name)));
new_part->header.checksum = nvram_checksum(&new_part->header); new_part->header.checksum = nvram_checksum(&new_part->header);
rc = nvram_write_header(new_part); rc = nvram_write_header(new_part);
......
...@@ -101,9 +101,9 @@ static u64 make_first_field(const char *text, u64 index) ...@@ -101,9 +101,9 @@ static u64 make_first_field(const char *text, u64 index)
static u64 make_field(const char *text, u64 index) static u64 make_field(const char *text, u64 index)
{ {
u64 n; u64 n = 0;
strncpy((char *)&n, text, 8); memcpy((char *)&n, text, strnlen(text, sizeof(n)));
return n + index; return n + index;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment