[v2] examples/vhost: fix potential overflow in args process

Message ID 20210427031401.4369-1-Cheng1.jiang@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series [v2] examples/vhost: fix potential overflow in args process |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Functional success Functional Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/github-robot success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Jiang, Cheng1 April 27, 2021, 3:14 a.m. UTC
  Change the way passing args to fix potential overflow in args process.

Coverity issue: 363741
Fixes: 965b06f0358 ("examples/vhost: enhance getopt_long usage")

Signed-off-by: Cheng Jiang <Cheng1.jiang@intel.com>
---
v2:
 * Change the way passing args
 * Change git log

 examples/vhost/main.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

--
2.29.2
  

Comments

Maxime Coquelin May 3, 2021, 2:01 p.m. UTC | #1
On 4/27/21 5:14 AM, Cheng Jiang wrote:
> Change the way passing args to fix potential overflow in args process.
> 
> Coverity issue: 363741
> Fixes: 965b06f0358 ("examples/vhost: enhance getopt_long usage")
> 
> Signed-off-by: Cheng Jiang <Cheng1.jiang@intel.com>
> ---
> v2:
>  * Change the way passing args
>  * Change git log
> 
>  examples/vhost/main.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  
Maxime Coquelin May 4, 2021, 8:28 a.m. UTC | #2
On 4/27/21 5:14 AM, Cheng Jiang wrote:
> Change the way passing args to fix potential overflow in args process.
> 
> Coverity issue: 363741
> Fixes: 965b06f0358 ("examples/vhost: enhance getopt_long usage")
> 
> Signed-off-by: Cheng Jiang <Cheng1.jiang@intel.com>
> ---
> v2:
>  * Change the way passing args
>  * Change git log
> 
>  examples/vhost/main.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 


Applied to dpdk-next-virtio/main.

Thanks,
Maxime
  

Patch

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 119ba7e01..3e2e9a45c 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -55,9 +55,6 @@ 

 #define INVALID_PORT_ID 0xFF

-/* Maximum long option length for option parsing. */
-#define MAX_LONG_OPT_SZ 64
-
 /* mask of enabled ports */
 static uint32_t enabled_port_mask = 0;

@@ -97,7 +94,7 @@  static int builtin_net_driver;

 static int async_vhost_driver;

-static char dma_type[MAX_LONG_OPT_SZ];
+static char *dma_type;

 /* Specify timeout (in useconds) between retries on RX. */
 static uint32_t burst_rx_delay_time = BURST_RX_WAIT_US;
@@ -201,7 +198,7 @@  struct vhost_bufftable *vhost_txbuff[RTE_MAX_LCORE * MAX_VHOST_DEVICE];
 static inline int
 open_dma(const char *value)
 {
-	if (strncmp(dma_type, "ioat", 4) == 0)
+	if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0)
 		return open_ioat(value);

 	return -1;
@@ -669,7 +666,7 @@  us_vhost_parse_args(int argc, char **argv)
 			break;

 		case OPT_DMA_TYPE_NUM:
-			strcpy(dma_type, optarg);
+			dma_type = optarg;
 			break;

 		case OPT_DMAS_NUM:
@@ -1472,7 +1469,7 @@  new_device(int vid)
 		struct rte_vhost_async_features f;
 		struct rte_vhost_async_channel_ops channel_ops;

-		if (strncmp(dma_type, "ioat", 4) == 0) {
+		if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) {
 			channel_ops.transfer_data = ioat_transfer_data_cb;
 			channel_ops.check_completed_copies =
 				ioat_check_completed_copies_cb;