All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Muhammad Bilal <m.bilal@emumba.com>
Cc: hemant.agrawal@nxp.com, olivier.matz@6wind.com, dev@dpdk.org,
	stable@dpdk.org
Subject: Re: [dpdk-dev] [PATCH] putting null checks on ops_name
Date: Mon, 6 Apr 2020 08:20:14 -0700	[thread overview]
Message-ID: <20200406082014.0c46bd90@hermes.lan> (raw)
In-Reply-To: <20200406113020.8074-1-m.bilal@emumba.com>

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

> Bugzilla ID: 353
> Cc: dev@dpdk.org
> Cc: stable@dpdk.org
> Cc: hemant.agrawal@nxp.com
> Signed-off-by: Muhammad Bilal <m.bilal@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;

  reply	other threads:[~2020-04-06 15:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-06 11:30 [dpdk-dev] [PATCH] putting null checks on ops_name Muhammad Bilal
2020-04-06 15:20 ` Stephen Hemminger [this message]
2020-04-07  7:56 ` [dpdk-dev] [PATCH v2] " Muhammad Bilal
2020-04-07 10:16   ` Hemant Agrawal
2020-04-25 20:59   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200406082014.0c46bd90@hermes.lan \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=hemant.agrawal@nxp.com \
    --cc=m.bilal@emumba.com \
    --cc=olivier.matz@6wind.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.