From: Dave Jiang <dave.jiang@intel.com>
To: Vishal Verma <vishal.l.verma@intel.com>, linux-nvdimm@lists.01.org
Subject: Re: [ndctl PATCH] libndctl: Fix a potentially non NUL-terminated string operation
Date: Fri, 20 Sep 2019 11:14:43 -0700 [thread overview]
Message-ID: <d602e9fd-8a39-d75b-f9dc-ed18c054c3ab@intel.com> (raw)
In-Reply-To: <20190920180608.8662-1-vishal.l.verma@intel.com>
On 9/20/19 11:06 AM, Vishal Verma wrote:
> Static analysis warns that pread() doesn't NUL-terminate buffers, and
> that we shouldn't pass it directly to strcmp. The sysfs string should
> normally have the right termination, but for correctness in the library,
> we shouldn't rely on that. Replace the strcmp() calls in question with
> an explicit strncmp().
>
> Fixes: 3c0c7db045ec ("ndctl: add a wait-overwrite command")
> Cc: Dave Jiang <dave.jiang@intel.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> ndctl/lib/dimm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/ndctl/lib/dimm.c b/ndctl/lib/dimm.c
> index 2f145be..17344f0 100644
> --- a/ndctl/lib/dimm.c
> +++ b/ndctl/lib/dimm.c
> @@ -825,7 +825,7 @@ NDCTL_EXPORT int ndctl_dimm_wait_overwrite(struct ndctl_dimm *dimm)
> break;
> }
>
> - if (strcmp(buf, "overwrite") == 0) {
> + if (strncmp(buf, "overwrite", 9) == 0) {
> rc = poll(&fds, 1, -1);
> if (rc < 0) {
> rc = -errno;
> @@ -839,7 +839,7 @@ NDCTL_EXPORT int ndctl_dimm_wait_overwrite(struct ndctl_dimm *dimm)
> }
> fds.revents = 0;
> } else {
> - if (strcmp(buf, "disabled") == 0)
> + if (strncmp(buf, "disabled", 8) == 0)
> rc = 1;
> break;
> }
>
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
prev parent reply other threads:[~2019-09-20 18:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-20 18:06 [ndctl PATCH] libndctl: Fix a potentially non NUL-terminated string operation Vishal Verma
2019-09-20 18:14 ` Dave Jiang [this message]
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=d602e9fd-8a39-d75b-f9dc-ed18c054c3ab@intel.com \
--to=dave.jiang@intel.com \
--cc=linux-nvdimm@lists.01.org \
--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;
as well as URLs for NNTP newsgroup(s).