OSDN Git Service

scsi: qedf: use correct strncpy() size
authorArnd Bergmann <arnd@arndb.de>
Fri, 2 Feb 2018 13:12:20 +0000 (14:12 +0100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Wed, 14 Feb 2018 02:37:02 +0000 (21:37 -0500)
gcc-8 warns during link-time optimization that the strncpy() call passes
the size of the source buffer rather than the destination:

drivers/scsi/qedf/qedf_dbg.c: In function 'qedf_uevent_emit':
include/linux/string.h:253: error: 'strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]

This changes it to strscpy() with the correct length, guaranteeing a
properly nul-terminated string of the right size.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Chad Dupuis <chad.dupuis@cavium.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/qedf/qedf_dbg.c

index e023f5d..bd1cef2 100644 (file)
@@ -160,7 +160,7 @@ qedf_uevent_emit(struct Scsi_Host *shost, u32 code, char *msg)
        switch (code) {
        case QEDF_UEVENT_CODE_GRCDUMP:
                if (msg)
-                       strncpy(event_string, msg, strlen(msg));
+                       strscpy(event_string, msg, sizeof(event_string));
                else
                        sprintf(event_string, "GRCDUMP=%u", shost->host_no);
                break;