All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: alison.schofield@intel.com, nvdimm@lists.linux.dev
Subject: Re: [ndctl PATCH 3/5] ndctl/dimm: do not increment a ULLONG_MAX slot value
Date: Wed, 5 Mar 2025 09:38:31 -0700	[thread overview]
Message-ID: <45c58eac-422d-4c19-ac2a-483eabb8579a@intel.com> (raw)
In-Reply-To: <6f3f15b368b1d2708f93f00325e009747425cef0.1741047738.git.alison.schofield@intel.com>



On 3/3/25 5:37 PM, alison.schofield@intel.com wrote:
> From: Alison Schofield <alison.schofield@intel.com>
> 
> A coverity scan higlighted an overflow issue when the slot variable,
> an unsigned integer that is initialized to -1, is incremented and
> overflows.
> 
> Initialize slot to 0 and move the increment statement to after slot
> is evaluated. That keeps the comparison to a u32 as is and avoids
> overflow.
> 
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> ---
>  ndctl/dimm.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/ndctl/dimm.c b/ndctl/dimm.c
> index 889b620355fc..c39c69bfa336 100644
> --- a/ndctl/dimm.c
> +++ b/ndctl/dimm.c
> @@ -97,7 +97,7 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm,
>  	struct json_object *jlabel = NULL;
>  	struct namespace_label nslabel;
>  	unsigned int nsindex_size;
> -	unsigned int slot = -1;
> +	unsigned int slot = 0;
>  	ssize_t offset;
>  
>  	if (!jarray)
> @@ -115,7 +115,6 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm,
>  		struct json_object *jobj;
>  		char uuid[40];
>  
> -		slot++;
>  		jlabel = json_object_new_object();
>  		if (!jlabel)
>  			break;
> @@ -127,8 +126,11 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm,
>  		if (len < 0)
>  			break;
>  
> -		if (le32_to_cpu(nslabel.slot) != slot)
> +		if (le32_to_cpu(nslabel.slot) != slot) {
> +			slot++;
>  			continue;
> +		}
> +		slot++;

Wonder if you can just increment the slot in the for() since it's not being used after this. 

>  
>  		uuid_unparse((void *) nslabel.uuid, uuid);
>  		jobj = json_object_new_string(uuid);


  reply	other threads:[~2025-03-05 16:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04  0:37 [ndctl PATCH 0/5] Address Coverity Scan Defects alison.schofield
2025-03-04  0:37 ` [ndctl PATCH 1/5] ndctl/namespace: avoid integer overflow in namespace validation alison.schofield
2025-03-05 16:24   ` Dave Jiang
2025-03-04  0:37 ` [ndctl PATCH 2/5] ndctl/namespace: close file descriptor in do_xaction_namespace() alison.schofield
2025-03-05 16:32   ` Dave Jiang
2025-03-04  0:37 ` [ndctl PATCH 3/5] ndctl/dimm: do not increment a ULLONG_MAX slot value alison.schofield
2025-03-05 16:38   ` Dave Jiang [this message]
2025-03-06 22:56     ` Alison Schofield
2025-03-04  0:37 ` [ndctl PATCH 4/5] ndctl/namespace: protect against overflow handling param.offset alison.schofield
2025-03-05 16:43   ` Dave Jiang
2025-03-04  0:37 ` [ndctl PATCH 5/5] ndctl/namespace: protect against under|over-flow w bad param.align alison.schofield
2025-03-05 16:43   ` Dave Jiang

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=45c58eac-422d-4c19-ac2a-483eabb8579a@intel.com \
    --to=dave.jiang@intel.com \
    --cc=alison.schofield@intel.com \
    --cc=nvdimm@lists.linux.dev \
    /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.