Skip to contentSkip to conversation

net/softnic: fix null pointer dereference

PATCH Applied [email protected] 3 participants 3 messages Jul 27, 2021 – Jul 30, 2021 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/softnic: fix null pointer dereference

From: Dapeng Yu <[email protected]>

When there is no "firmware" in arguments, the "firmware" pointer is null, and will be dereferenced by rte_strscpy().

This patch moves the code block which copies character string from "firmware" to "p->firmware" into the "if" statements where "firmware" argument exists and it is duplicated successfully.

Coverity issue: 372136

Fixes d8f852f5f369 ("net/softnic: fix memory leak in arguments parsing")
---
 drivers/net/softnic/rte_eth_softnic.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/net/softnic/rte_eth_softnic.c +11 -9
index 0aa7147b13..b3b55b9035 100644
@@ -479,17 +479,19 @@ pmd_parse_args(struct pmd_params *p, const char *params)
 			&get_string, &firmware);
 		if (ret < 0)
 			goto out_free;
-	}
-	if (rte_strscpy(p->firmware, firmware,
-			sizeof(p->firmware)) < 0) {
-		PMD_LOG(WARNING,
-			"\"%s\": firmware path should be shorter than %zu",
-			firmware, sizeof(p->firmware));
+
+		if (rte_strscpy(p->firmware, firmware,
+				sizeof(p->firmware)) < 0) {
+			PMD_LOG(WARNING,
+				"\"%s\": "
+				"firmware path should be shorter than %zu",
+				firmware, sizeof(p->firmware));
+			free(firmware);
+			ret = -EINVAL;
+			goto out_free;
+		}
 		free(firmware);
-		ret = -EINVAL;
-		goto out_free;
 	}
-	free(firmware);
 	/* Connection listening port (optional) */
 	if (rte_kvargs_count(kvlist, PMD_PARAM_CONN_PORT) == 1) {
 		ret = rte_kvargs_process(kvlist, PMD_PARAM_CONN_PORT,
Signature · 1 line
2.27.0
Acked-by on v1 1/1
#1 lore raw
Quoted 19 lines

-----Original Message-----
From: Yu, DapengX <[email protected]>
Sent: Tuesday, July 27, 2021 9:15 AM
To: Singh, Jasvinder <[email protected]>; Dumitrescu, Cristian <[email protected]>
Cc: [email protected]; Yu, DapengX <[email protected]>; [email protected]
Subject: [PATCH] net/softnic: fix null pointer dereference

From: Dapeng Yu <[email protected]>

When there is no "firmware" in arguments, the "firmware" pointer is null, and will be dereferenced by rte_strscpy().

This patch moves the code block which copies character string from "firmware" to "p->firmware" into the "if" statements where "firmware" argument exists and it is duplicated successfully.

Quoted 6 lines

Coverity issue: 372136

Fixes d8f852f5f369 ("net/softnic: fix memory leak in arguments parsing")

---

#2 lore raw
Quoted 9 lines
Quoted 9 lines

From: Dapeng Yu <[email protected]>

When there is no "firmware" in arguments, the "firmware" pointer is null, and will be dereferenced by rte_strscpy().

This patch moves the code block which copies character string from "firmware" to "p->firmware" into the "if" statements where "firmware" argument exists and it is duplicated successfully.

Quoted 7 lines
Quoted 5 lines

Coverity issue: 372136

Fixes d8f852f5f369 ("net/softnic: fix memory leak in arguments parsing")

Applied, thanks.