diff mbox series

[v1] examples/vhost: fix missing args length check

Message ID 20201106032401.9149-1-Cheng1.jiang@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers show
Series [v1] examples/vhost: fix missing args length check | expand

Checks

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

Commit Message

Cheng Jiang Nov. 6, 2020, 3:24 a.m. UTC
Add args length check before copying to fix the coverity issue.

Fixes: 3a04ecb21420 ("examples/vhost: add async vhost args parsing")
Coverity issue: 363741

Signed-off-by: Cheng Jiang <Cheng1.jiang@intel.com>
---
 examples/vhost/main.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Maxime Coquelin Nov. 10, 2020, 9:44 a.m. UTC | #1
On 11/6/20 4:24 AM, Cheng Jiang wrote:
> Add args length check before copying to fix the coverity issue.
> 
> Fixes: 3a04ecb21420 ("examples/vhost: add async vhost args parsing")
> Coverity issue: 363741
> 
> Signed-off-by: Cheng Jiang <Cheng1.jiang@intel.com>
> ---
>  examples/vhost/main.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/examples/vhost/main.c b/examples/vhost/main.c
> index 59a1aff07c..ec88874d16 100644
> --- a/examples/vhost/main.c
> +++ b/examples/vhost/main.c
> @@ -634,6 +634,12 @@ us_vhost_parse_args(int argc, char **argv)
>  
>  			if (!strncmp(long_option[option_index].name,
>  						"dma-type", MAX_LONG_OPT_SZ)) {
> +				if (strlen(optarg) >= MAX_LONG_OPT_SZ) {
> +					RTE_LOG(INFO, VHOST_CONFIG,
> +						"Wrong DMA type\n");
> +					us_vhost_usage(prgname);
> +					return -1;
> +				}
>  				strcpy(dma_type, optarg);
>  			}
>  
> 

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

Thanks,
Maxime
Maxime Coquelin Nov. 13, 2020, 8:41 a.m. UTC | #2
On 11/6/20 4:24 AM, Cheng Jiang wrote:
> Add args length check before copying to fix the coverity issue.
> 
> Fixes: 3a04ecb21420 ("examples/vhost: add async vhost args parsing")
> Coverity issue: 363741
> 
> Signed-off-by: Cheng Jiang <Cheng1.jiang@intel.com>
> ---
>  examples/vhost/main.c | 6 ++++++
>  1 file changed, 6 insertions(+)

Applied to dpdk-next-virtio/main.

Thanks,
Maxime
diff mbox series

Patch

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 59a1aff07c..ec88874d16 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -634,6 +634,12 @@  us_vhost_parse_args(int argc, char **argv)
 
 			if (!strncmp(long_option[option_index].name,
 						"dma-type", MAX_LONG_OPT_SZ)) {
+				if (strlen(optarg) >= MAX_LONG_OPT_SZ) {
+					RTE_LOG(INFO, VHOST_CONFIG,
+						"Wrong DMA type\n");
+					us_vhost_usage(prgname);
+					return -1;
+				}
 				strcpy(dma_type, optarg);
 			}