[1/3] crypto/octeontx: fix non null terminated string

Message ID 1541949837-9629-2-git-send-email-anoob.joseph@caviumnetworks.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series fixing coverity reported issues |

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Anoob Joseph Nov. 11, 2018, 3:24 p.m. UTC
  If the length of string pointed by 'name' is equal to or greater than
the sizeof cptvf->dev_name string, the resultant string will not be
null terminated. Using strlcpy would make sure the string would always
be null terminated.

Fixes: 0dc1cffa4d33 ("crypto/octeontx: add hardware init routine")

Signed-off-by: Ankur Dwivedi <ankur.dwivedi@caviumnetworks.com>
Signed-off-by: Anoob Joseph <anoob.joseph@caviumnetworks.com>
---
 drivers/crypto/octeontx/otx_cryptodev_hw_access.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/crypto/octeontx/otx_cryptodev_hw_access.c b/drivers/crypto/octeontx/otx_cryptodev_hw_access.c
index 5e705a8..18f2e6b 100644
--- a/drivers/crypto/octeontx/otx_cryptodev_hw_access.c
+++ b/drivers/crypto/octeontx/otx_cryptodev_hw_access.c
@@ -9,6 +9,7 @@ 
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_memzone.h>
+#include <rte_string_fns.h>
 
 #include "otx_cryptodev_hw_access.h"
 #include "otx_cryptodev_mbox.h"
@@ -366,7 +367,9 @@  otx_cpt_hw_init(struct cpt_vf *cptvf, void *pdev, void *reg_base, char *name)
 
 	/* Bar0 base address */
 	cptvf->reg_base = reg_base;
-	strncpy(cptvf->dev_name, name, 32);
+
+	/* Save device name */
+	strlcpy(cptvf->dev_name, name, (sizeof(cptvf->dev_name)));
 
 	cptvf->pdev = pdev;