diff mbox series

[6/6] scsi: qedf: use correct strncpy() size

Message ID 20180202131225.1658853-7-arnd@arndb.de
State New
Headers show
Series scsi: fixes for building with LTO | expand

Commit Message

Arnd Bergmann Feb. 2, 2018, 1:12 p.m. UTC
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>

---
 drivers/scsi/qedf/qedf_dbg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.9.0

Comments

kernel test robot Feb. 5, 2018, 2:56 a.m. UTC | #1
Hi Arnd,

I love your patch! Perhaps something to improve:

[auto build test WARNING on scsi/for-next]
[also build test WARNING on v4.15]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Arnd-Bergmann/scsi-fixes-for-building-with-LTO/20180205-083607
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
config: xtensa-allmodconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=xtensa 

All warnings (new ones prefixed by >>):

   drivers/scsi//qedf/qedf_dbg.c: In function 'qedf_uevent_emit':
>> drivers/scsi//qedf/qedf_dbg.c:163:4: warning: ignoring return value of 'strscpy', declared with attribute warn_unused_result [-Wunused-result]

       strscpy(event_string, msg, sizeof(event_string));
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/strscpy +163 drivers/scsi//qedf/qedf_dbg.c

   152	
   153	void
   154	qedf_uevent_emit(struct Scsi_Host *shost, u32 code, char *msg)
   155	{
   156		char event_string[40];
   157		char *envp[] = {event_string, NULL};
   158	
   159		memset(event_string, 0, sizeof(event_string));
   160		switch (code) {
   161		case QEDF_UEVENT_CODE_GRCDUMP:
   162			if (msg)
 > 163				strscpy(event_string, msg, sizeof(event_string));

   164			else
   165				sprintf(event_string, "GRCDUMP=%u", shost->host_no);
   166			break;
   167		default:
   168			/* do nothing */
   169			break;
   170		}
   171	
   172		kobject_uevent_env(&shost->shost_gendev.kobj, KOBJ_CHANGE, envp);
   173	}
   174	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Martin K. Petersen Feb. 9, 2018, 11:36 p.m. UTC | #2
Arnd,

> gcc-8 warns during link-time optimization that the strncpy() call

> passes the size of the source buffer rather than the destination:


Applied to 4.17/scsi-queue. Thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering
diff mbox series

Patch

diff --git a/drivers/scsi/qedf/qedf_dbg.c b/drivers/scsi/qedf/qedf_dbg.c
index e023f5d0dc12..bd1cef25a900 100644
--- a/drivers/scsi/qedf/qedf_dbg.c
+++ b/drivers/scsi/qedf/qedf_dbg.c
@@ -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;