All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vishal Verma <vishal.l.verma@intel.com>
To: nvdimm@lists.linux.dev
Cc: Dan Williams <dan.j.williams@intel.com>,
	 Vishal Verma <vishal.l.verma@intel.com>
Subject: [PATCH ndctl] ndctl/namespace.c: fix unchecked return value from uuid_parse()
Date: Tue, 02 May 2023 13:40:46 -0600	[thread overview]
Message-ID: <20230502-vv-coverity-v1-1-079352646ba2@intel.com> (raw)

Static analysis reports that write_pfn_sb() neglects to check the return
value from uuid_parse as is done elsewhere. Since the uuid being parsed
comes from the user, check for failure, and return an EINVAL if so.

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/namespace.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 722f13a..aa8c23a 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -1869,15 +1869,19 @@ static int write_pfn_sb(int fd, unsigned long long size, const char *sig,
 	npfns = PHYS_PFN(size - SZ_8K);
 	pfn_align = parse_size64(param.align);
 	align = max(pfn_align, SUBSECTION_SIZE);
-	if (param.uuid)
-		uuid_parse(param.uuid, uuid);
-	else
+	if (param.uuid) {
+		if (uuid_parse(param.uuid, uuid))
+			return -EINVAL;
+	} else {
 		uuid_generate(uuid);
+	}
 
-	if (param.parent_uuid)
-		uuid_parse(param.parent_uuid, parent_uuid);
-	else
+	if (param.parent_uuid) {
+		if (uuid_parse(param.parent_uuid, parent_uuid))
+			return -EINVAL;
+	} else {
 		memset(parent_uuid, 0, sizeof(uuid_t));
+	}
 
 	if (strcmp(param.map, "dev") == 0)
 		mode = PFN_MODE_PMEM;

---
base-commit: 26d9ce3351361631677e2cae933e3641540fa807
change-id: 20230502-vv-coverity-d3a9dc40abd6

Best regards,
-- 
Vishal Verma <vishal.l.verma@intel.com>


             reply	other threads:[~2023-05-02 19:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-02 19:40 Vishal Verma [this message]
2023-05-02 19:48 ` [PATCH ndctl] ndctl/namespace.c: fix unchecked return value from uuid_parse() Dan Williams

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=20230502-vv-coverity-v1-1-079352646ba2@intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=dan.j.williams@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.