]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: qed: use correct strncpy() size
authorArnd Bergmann <arnd@arndb.de>
Fri, 2 Feb 2018 15:44:47 +0000 (16:44 +0100)
committerDavid S. Miller <davem@davemloft.net>
Sat, 3 Feb 2018 00:42:29 +0000 (19:42 -0500)
passing the strlen() of the source string as the destination
length is pointless, and gcc-8 now warns about it:

drivers/net/ethernet/qlogic/qed/qed_debug.c: In function 'qed_grc_dump':
include/linux/string.h:253: error: 'strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]

This changes qed_grc_dump_big_ram() to instead uses the length of
the destination buffer, and use strscpy() to guarantee nul-termination.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/qlogic/qed/qed_debug.c

index f2633ec87a6afb07cbfce0e20b556abc35df63c2..fdf37abee3d382e3859a8c303b2c1ab81ebf8c65 100644 (file)
@@ -3649,10 +3649,8 @@ static u32 qed_grc_dump_big_ram(struct qed_hwfn *p_hwfn,
                     BIT(big_ram->is_256b_bit_offset[dev_data->chip_id]) ? 256
                                                                         : 128;
 
-       strncpy(type_name, big_ram->instance_name,
-               strlen(big_ram->instance_name));
-       strncpy(mem_name, big_ram->instance_name,
-               strlen(big_ram->instance_name));
+       strscpy(type_name, big_ram->instance_name, sizeof(type_name));
+       strscpy(mem_name, big_ram->instance_name, sizeof(mem_name));
 
        /* Dump memory header */
        offset += qed_grc_dump_mem_hdr(p_hwfn,