[dpdk-dev] [PATCH] putting null checks on ops_name

Stephen Hemminger stephen at networkplumber.org
Mon Apr 6 17:20:14 CEST 2020


On Mon,  6 Apr 2020 16:30:20 +0500
Muhammad Bilal <m.bilal at emumba.com> wrote:

> Bugzilla ID: 353
> Cc: dev at dpdk.org
> Cc: stable at dpdk.org
> Cc: hemant.agrawal at nxp.com
> Signed-off-by: Muhammad Bilal <m.bilal at emumba.com>
> ---
>  lib/librte_mbuf/rte_mbuf_pool_ops.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/librte_mbuf/rte_mbuf_pool_ops.c b/lib/librte_mbuf/rte_mbuf_pool_ops.c
> index 5722976fe..c3ddfc0bd 100644
> --- a/lib/librte_mbuf/rte_mbuf_pool_ops.c
> +++ b/lib/librte_mbuf/rte_mbuf_pool_ops.c
> @@ -13,7 +13,8 @@ int
>  rte_mbuf_set_platform_mempool_ops(const char *ops_name)
>  {
>  	const struct rte_memzone *mz;
> -
> +	if (strlen(ops_name) == 0)
> +		return -1;
>  	if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
>  		return -ENAMETOOLONG;
>  
> @@ -50,7 +51,8 @@ int
>  rte_mbuf_set_user_mempool_ops(const char *ops_name)
>  {
>  	const struct rte_memzone *mz;
> -
> +	if (strlen(ops_name) == 0)
> +		return -1;
>  	if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
>  		return -ENAMETOOLONG;
>  

If you want to do it simpler and safer use strnlen.
Also, don't mix -1 wit -errno returns.

	size_t len = strnlen(ops_name, RTE_MEMPOOL_OPS_NAMESIZE);

	if (len == 0)
		return -EINVAL;

	if (len == RTE_MEMPOOL_OPS_NAMESIZE)
		return -ENAMETOOLONG;


More information about the dev mailing list