Skip to contentSkip to conversation

examples/vhost: fix missing args length check

PATCH Applied Cheng Jiang 2 participants 3 messages Nov 6, 2020 – Nov 13, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/vhost: fix missing args length check

Add args length check before copying to fix the coverity issue.

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

Coverity issue: 363741

---
 examples/vhost/main.c | 6 ++++++
 1 file changed, 6 insertions(+)
examples/vhost/main.c +6 -0
index 59a1aff07c..ec88874d16 100644
@@ -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);
 			}
 
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Cheng Jiang

Add args length check before copying to fix the coverity issue.

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

Coverity issue: 363741

---
 examples/vhost/main.c | 6 ++++++
 1 file changed, 6 insertions(+)
examples/vhost/main.c +0 -0
index 59a1aff07c..ec88874d16 100644
@@ -634,6 +634,12 @@ us_vhost_parse_args(int argc, char **argv)
 
 			if (!strncmp(long_option[option_index].name,

examples/vhost/main.c us_vhost_parse_args(int argc, char **argv) · line 645

Quoted 10 lines
examples/vhost/main.c +6 -0
 						"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);
 			}
 

Thanks,
Maxime

#2 lore raw
In reply to Cheng Jiang
Quoted 9 lines · Cheng Jiang

Add args length check before copying to fix the coverity issue.

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

Coverity issue: 363741

---
 examples/vhost/main.c | 6 ++++++
 1 file changed, 6 insertions(+)

Applied to dpdk-next-virtio/main.

Thanks,
Maxime