DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Shetty, Praveen" <praveen.shetty@intel.com>
To: "Richardson, Bruce" <bruce.richardson@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>, "stable@dpdk.org" <stable@dpdk.org>
Subject: RE: [PATCH v2] net/cpfl: fix cpfl parser issue
Date: Fri, 23 Aug 2024 07:28:32 +0000	[thread overview]
Message-ID: <MW4PR11MB5911543C2A295515CD9683719D882@MW4PR11MB5911.namprd11.prod.outlook.com> (raw)
In-Reply-To: <ZsdsXrjCjAWPQOib@bricha3-mobl1.ger.corp.intel.com>

> CPFL parser was incorrectly parsing the mask value of the 
> next_proto_id field from recipe.json file as a string instead of 
> unsigned integer.
> 
> Fixes: 41f20298ee8c ("net/cpfl: parse flow offloading hint from JSON")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Praveen Shetty <praveen.shetty@intel.com>
> 
> ---
> v2:
> * Fixed CI issues.
> ---
>  drivers/net/cpfl/cpfl_flow_parser.c | 34 
> +++++++++++++++++++----------
>  1 file changed, 22 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/cpfl/cpfl_flow_parser.c 
> b/drivers/net/cpfl/cpfl_flow_parser.c
> index 40569ddc6f..7800ad97ea 100644
> --- a/drivers/net/cpfl/cpfl_flow_parser.c
> +++ b/drivers/net/cpfl/cpfl_flow_parser.c
> @@ -198,6 +198,8 @@ cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
>  	for (i = 0; i < len; i++) {
>  		json_t *object;
>  		const char *name, *mask;
> +		uint32_t mask_32b = 0;
> +		int ret;
>  
>  		object = json_array_get(ob_fields, i);
>  		name = cpfl_json_t_to_string(object, "name"); @@ -213,20 +215,28 @@ 
> cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
>  
>  		if (js_field->type == RTE_FLOW_ITEM_TYPE_ETH ||
>  		    js_field->type == RTE_FLOW_ITEM_TYPE_IPV4) {
> -			mask = cpfl_json_t_to_string(object, "mask");
> -			if (!mask) {
> -				PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
> -				goto err;
> -			}
> -			if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
> -				PMD_DRV_LOG(ERR, "The 'mask' is too long.");
> -				goto err;
> +			/* Added a check for parsing mask value of the next_proto_id field. */
> +			if (strcmp(name, "next_proto_id") == 0) {
> +				ret = cpfl_json_t_to_uint32(object, "mask", &mask_32b);
> +				if (ret < 0) {
> +					PMD_DRV_LOG(ERR, "Cannot parse uint32 'mask'.");
> +					goto err;
> +				}
> +				js_field->fields[i].mask_32b = mask_32b;
> +			} else {
> +				mask = cpfl_json_t_to_string(object, "mask");
> +				if (!mask) {
> +					PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
> +					goto err;
> +				}
> +				if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
> +					PMD_DRV_LOG(ERR, "The 'mask' is too long.");
> +					goto err;
> +				}
> +				rte_strscpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE - 
> +1);

+1 for replacing strncpy with something safer, since original code is 
+wrong
and can leave a non-null-terminated string, but unfortunately the copy here isn't quite right. For strlcpy and rte_strscpy, you specify the exact buffer size, not the size-1.

Also, you don't need to check the length and then do the copy, you might as well just do the copy using strscpy or strlcpy and check the return value from it. Saves iterating the string twice (once for length, second time for copy). For example:

  if (rte_strscpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE) < 0) {
  	PMD_DRV_LOG(ERR, "The 'mask' is too long.");
  	goto err;
  }

Thanks, will fix this in v3.

Regards,
/Bruce

  reply	other threads:[~2024-08-23  7:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-30  5:09 [PATCH v1] " Praveen Shetty
2024-07-31  7:23 ` [PATCH v2] " Praveen Shetty
2024-08-22 16:50   ` Bruce Richardson
2024-08-23  7:28     ` Shetty, Praveen [this message]
2024-08-23 11:14   ` [PATCH v3] " Praveen Shetty
2024-08-26 15:32     ` Bruce Richardson

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=MW4PR11MB5911543C2A295515CD9683719D882@MW4PR11MB5911.namprd11.prod.outlook.com \
    --to=praveen.shetty@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).