Skip to content

Commit

Permalink
net/softnic: fix null dereference in arguments parsing
Browse files Browse the repository at this point in the history
[ upstream commit 51799b4 ]

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: d8f852f ("net/softnic: fix memory leak in arguments parsing")

Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
Acked-by: Jasvinder Singh <jasvinder.singh@intel.com>
  • Loading branch information
yudapengx authored and cpaelzer committed Aug 10, 2021
1 parent a4cb6c2 commit 0eaed42
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions drivers/net/softnic/rte_eth_softnic.c
Expand Up @@ -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,
Expand Down

0 comments on commit 0eaed42

Please sign in to comment.