[1/4] net/softnic: fix string copy

Message ID 1540909372-23110-1-git-send-email-reshma.pattan@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [1/4] net/softnic: fix string copy |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Pattan, Reshma Oct. 30, 2018, 2:22 p.m. UTC
  From: Reshma Pattan <reshma.pattan@intel.com>

Use strlcpy instead of strcpy to avoid buffer overrun.

Coverity issue: 323514

Fixes: b767f8efc8 ("net/softnic: replace pointers with arrays")
CC: cristian.dumitrescu@intel.com
CC: jasvinder.singh@intel.com

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
 drivers/net/softnic/rte_eth_softnic_cli.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Thomas Monjalon Oct. 31, 2018, 9:47 a.m. UTC | #1
Hi Reshma,

30/10/2018 15:22, Reshma Pattan:
> From: Reshma Pattan <reshma.pattan@intel.com>
> 
> Use strlcpy instead of strcpy to avoid buffer overrun.
> 
> Coverity issue: 323514
> 
> Fixes: b767f8efc8 ("net/softnic: replace pointers with arrays")
> CC: cristian.dumitrescu@intel.com
> CC: jasvinder.singh@intel.com
> 
> Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>

The 4 patches in this series have the same title,
same explanation and same root cause.
Only the coverity ID is changing.
In this case, you can merge all patches together
and reference all coverity ids on the same line with commas.
  

Patch

diff --git a/drivers/net/softnic/rte_eth_softnic_cli.c b/drivers/net/softnic/rte_eth_softnic_cli.c
index c6640d658..2235b07e8 100644
--- a/drivers/net/softnic/rte_eth_softnic_cli.c
+++ b/drivers/net/softnic/rte_eth_softnic_cli.c
@@ -2096,7 +2096,7 @@  cmd_pipeline_port_out(struct pmd_internals *softnic,
 
 		p.type = PORT_OUT_TXQ;
 
-		strcpy(p.dev_name, tokens[7]);
+		strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
 
 		if (strcmp(tokens[8], "txq") != 0) {
 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
@@ -2117,7 +2117,7 @@  cmd_pipeline_port_out(struct pmd_internals *softnic,
 
 		p.type = PORT_OUT_SWQ;
 
-		strcpy(p.dev_name, tokens[7]);
+		strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
 	} else if (strcmp(tokens[6], "tmgr") == 0) {
 		if (n_tokens != 8) {
 			snprintf(out, out_size, MSG_ARG_MISMATCH,
@@ -2127,7 +2127,7 @@  cmd_pipeline_port_out(struct pmd_internals *softnic,
 
 		p.type = PORT_OUT_TMGR;
 
-		strcpy(p.dev_name, tokens[7]);
+		strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
 	} else if (strcmp(tokens[6], "tap") == 0) {
 		if (n_tokens != 8) {
 			snprintf(out, out_size, MSG_ARG_MISMATCH,
@@ -2137,7 +2137,7 @@  cmd_pipeline_port_out(struct pmd_internals *softnic,
 
 		p.type = PORT_OUT_TAP;
 
-		strcpy(p.dev_name, tokens[7]);
+		strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
 	} else if (strcmp(tokens[6], "sink") == 0) {
 		if ((n_tokens != 7) && (n_tokens != 11)) {
 			snprintf(out, out_size, MSG_ARG_MISMATCH,