Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1322376 > unrolled thread

[patch] bfa: use strncpy() instead of memcpy()

Started byDan Carpenter <dan.carpenter@oracle.com>
First post2016-01-30 15:40 +0100
Last post2016-02-04 04:00 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [patch] bfa: use strncpy() instead of memcpy() Dan Carpenter <dan.carpenter@oracle.com> - 2016-01-30 15:40 +0100
    RE: [patch] bfa: use strncpy() instead of memcpy() Anil Gurumurthy <Anil.Gurumurthy@qlogic.com> - 2016-02-03 08:00 +0100
    Re: [patch] bfa: use strncpy() instead of memcpy() "Martin K. Petersen" <martin.petersen@oracle.com> - 2016-02-04 04:00 +0100

#1322376 — [patch] bfa: use strncpy() instead of memcpy()

FromDan Carpenter <dan.carpenter@oracle.com>
Date2016-01-30 15:40 +0100
Subject[patch] bfa: use strncpy() instead of memcpy()
Message-ID<qWEQW-4yb-11@gated-at.bofh.it>
BFA_MFG_NAME is "QLogic" which is only 7 bytes, but we are copying 8
bytes.  It's harmless because the badding byte is likely zero but it
makes static checkers complain.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Technically the memset() is not needed because strncpy() will pad the
rest of the buffer with zeros but I was worried that people would be
paranoid.

diff --git a/drivers/scsi/bfa/bfa_ioc.c b/drivers/scsi/bfa/bfa_ioc.c
index 251e2ff..a1ada4a 100644
--- a/drivers/scsi/bfa/bfa_ioc.c
+++ b/drivers/scsi/bfa/bfa_ioc.c
@@ -2803,7 +2803,7 @@ void
 bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
 {
 	memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
-	memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
+	strncpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
 }
 
 void

[toc] | [next] | [standalone]


#1324969

FromAnil Gurumurthy <Anil.Gurumurthy@qlogic.com>
Date2016-02-03 08:00 +0100
Message-ID<qXZzY-6PO-1@gated-at.bofh.it>
In reply to#1322376
Acked-by: Anil Gurumurthy <anil.gurumurthy@qlogic.com>

-----Original Message-----
From: Dan Carpenter [mailto:dan.carpenter@oracle.com] 
Sent: 30 January 2016 20:06
To: Anil Gurumurthy <Anil.Gurumurthy@qlogic.com>
Cc: Sudarsana Kalluru <Sudarsana.Kalluru@qlogic.com>; James E.J. Bottomley <JBottomley@odin.com>; Martin K. Petersen <martin.petersen@oracle.com>; linux-scsi <linux-scsi@vger.kernel.org>; linux-kernel <linux-kernel@vger.kernel.org>; kernel-janitors@vger.kernel.org
Subject: [patch] bfa: use strncpy() instead of memcpy()

BFA_MFG_NAME is "QLogic" which is only 7 bytes, but we are copying 8 bytes.  It's harmless because the badding byte is likely zero but it makes static checkers complain.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Technically the memset() is not needed because strncpy() will pad the rest of the buffer with zeros but I was worried that people would be paranoid.

diff --git a/drivers/scsi/bfa/bfa_ioc.c b/drivers/scsi/bfa/bfa_ioc.c index 251e2ff..a1ada4a 100644
--- a/drivers/scsi/bfa/bfa_ioc.c
+++ b/drivers/scsi/bfa/bfa_ioc.c
@@ -2803,7 +2803,7 @@ void
 bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)  {
 	memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
-	memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
+	strncpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
 }
 
 void

[toc] | [prev] | [next] | [standalone]


#1326356

From"Martin K. Petersen" <martin.petersen@oracle.com>
Date2016-02-04 04:00 +0100
Message-ID<qYijf-2w0-1@gated-at.bofh.it>
In reply to#1322376
>>>>> "Dan" == Dan Carpenter <dan.carpenter@oracle.com> writes:

Dan> BFA_MFG_NAME is "QLogic" which is only 7 bytes, but we are copying
Dan> 8 bytes.  It's harmless because the badding byte is likely zero but
Dan> it makes static checkers complain.

Applied to 4.6/scsi-queue.

-- 
Martin K. Petersen	Oracle Linux Engineering

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web