mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Pantyukhin <apantykhin@gmail.com>
To: andriy.shevchenko@linux.intel.com
Cc: hch@lst.de, linux-kernel@vger.kernel.org,
	Alexander Pantyukhin <apantykhin@gmail.com>
Subject: [PATCH] kib/uuid.c: add check for length for uuid_is_valid
Date: Sat, 21 Jan 2023 02:38:02 +0500	[thread overview]
Message-ID: <20230120213802.2467-1-apantykhin@gmail.com> (raw)

Add check for length strict equality for uuid is valid

Signed-off-by: Alexander Pantyukhin <apantykhin@gmail.com>
---
 lib/test_uuid.c | 1 +
 lib/uuid.c      | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/lib/test_uuid.c b/lib/test_uuid.c
index cd819c397dc7..7a3d258fa695 100644
--- a/lib/test_uuid.c
+++ b/lib/test_uuid.c
@@ -37,6 +37,7 @@ static const char * const test_uuid_wrong_data[] = {
 	"c33f4995-3701-450e-9fbf206a2e98e576 ",	/* no hyphen(s) */
 	"64b4371c-77c1-48f9-8221-29f054XX023b",	/* invalid character(s) */
 	"0cb4ddff-a545-4401-9d06-688af53e",	/* not enough data */
+	"0cb4ddff-a545-4401-9d06-688af53e7f8412" /* too much data */
 };
 
 static unsigned total_tests __initdata;
diff --git a/lib/uuid.c b/lib/uuid.c
index e309b4c5be3d..ca10e2b4334b 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -89,6 +89,9 @@ bool uuid_is_valid(const char *uuid)
 {
 	unsigned int i;
 
+	if (strlen(uuid) != UUID_STRING_LEN)
+		return false;
+
 	for (i = 0; i < UUID_STRING_LEN; i++) {
 		if (i == 8 || i == 13 || i == 18 || i == 23) {
 			if (uuid[i] != '-')
-- 
2.25.1


             reply	other threads:[~2023-01-20 21:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20 21:38 Alexander Pantyukhin [this message]
2023-01-21 10:50 ` Andy Shevchenko

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=20230120213802.2467-1-apantykhin@gmail.com \
    --to=apantykhin@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®