Linux CXL
 help / color / mirror / Atom feed
From: Alison Schofield <alison.schofield@intel.com>
To: Vishal Verma <vishal.l.verma@intel.com>
Cc: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev,
	Dave Jiang <dave.jiang@intel.com>,
	Dan Williams <dan.j.williams@intel.com>
Subject: Re: [PATCH ndctl 1/4] ndctl/lib: fix usage of a non NUL-terminated string
Date: Wed, 11 Jan 2023 14:45:59 -0800	[thread overview]
Message-ID: <Y788J2sr4WaE9V3i@aschofie-mobl2> (raw)
In-Reply-To: <20230110-vv-coverity-fixes-v1-1-c7ee6c76b200@intel.com>

On Tue, Jan 10, 2023 at 04:09:14PM -0700, Vishal Verma wrote:
> Static analysis reports that in add_region(), a buffer from pread()
> won't have NUL-termination. Hence passing it to strtol subsequently can
> be wrong. Manually add the termination after pread() to fix this.
> 
> Fixes: c64cc150a21e ("ndctl: add support in libndctl to provide deep flush")
> Cc: Dave Jiang <dave.jiang@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
> ---
>  ndctl/lib/libndctl.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
> index f32f704..ddbdd9a 100644
> --- a/ndctl/lib/libndctl.c
> +++ b/ndctl/lib/libndctl.c
> @@ -2750,6 +2750,8 @@ static void *add_region(void *parent, int id, const char *region_base)
>  		goto out;
>  	}
>  
> +	/* pread() doesn't add NUL termination */
> +	buf[1] = 0;
>  	perm = strtol(buf, NULL, 0);
>  	if (perm == 0) {
>  		close(region->flush_fd);
> 

This diff is annoying because it didn't include enough to show the
pread().  Made me open up file ;)

Reviewed-by: Alison Schofield <alison.schofield@intel.com>


> -- 
> 2.39.0
> 

  reply	other threads:[~2023-01-11 22:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10 23:09 [PATCH ndctl 0/4] cxl: misc coverity and typo fixes Vishal Verma
2023-01-10 23:09 ` [PATCH ndctl 1/4] ndctl/lib: fix usage of a non NUL-terminated string Vishal Verma
2023-01-11 22:45   ` Alison Schofield [this message]
2023-01-10 23:09 ` [PATCH ndctl 2/4] cxl/region: fix a resource leak in to_csv() Vishal Verma
2023-01-11 22:52   ` Alison Schofield
2023-01-10 23:09 ` [PATCH ndctl 3/4] cxl/region: fix an out of bounds access " Vishal Verma
2023-01-11 22:53   ` Alison Schofield
2023-01-10 23:09 ` [PATCH ndctl 4/4] cxl/region: fix a comment typo Vishal Verma
2023-01-11 22:54   ` Alison Schofield

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=Y788J2sr4WaE9V3i@aschofie-mobl2 \
    --to=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    /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