mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] cmdlinepart: refuse partitions with empty name
Date: Sun, 16 Feb 2025 16:07:18 +0100	[thread overview]
Message-ID: <20250216150718.2348520-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250216150718.2348520-1-a.fatoum@pengutronix.de>

Running addpart /dev/mmc3 0xe0000@0 currently creates a partition with a
zero-sized name. Check for this condition and throw an error.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/cmdlinepart.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/cmdlinepart.c b/lib/cmdlinepart.c
index afba544965b4..3e8c415c7ea6 100644
--- a/lib/cmdlinepart.c
+++ b/lib/cmdlinepart.c
@@ -30,6 +30,7 @@ int cmdlinepart_do_parse_one(const char *devname, const char *partstr,
 	char *end;
 	char buf[PATH_MAX] = {};
 	unsigned long flags = DEVFS_PARTITION_FOR_FIXUP;
+	size_t partname_len = 0;
 	struct cdev *cdev;
 
 	memset(buf, 0, PATH_MAX);
@@ -60,7 +61,8 @@ int cmdlinepart_do_parse_one(const char *devname, const char *partstr,
 		if ((partition_flags & CMDLINEPART_ADD_DEVNAME) &&
 				strncmp(devname, partstr, strlen(devname)))
 			sprintf(buf, "%s.", devname);
-		memcpy(buf + strlen(buf), partstr, end - partstr);
+		partname_len = end - partstr;
+		memcpy(buf + strlen(buf), partstr, partname_len);
 
 		end++;
 	}
@@ -85,6 +87,11 @@ int cmdlinepart_do_parse_one(const char *devname, const char *partstr,
 
 	*retsize = size;
 
+	if (!partname_len) {
+		printf("partition name can't be empty\n");
+		return -EINVAL;
+	}
+
 	cdev = devfs_add_partition(devname, *offset, size, flags, buf);
 	if (IS_ERR(cdev)) {
 		printf("cannot create %s: %pe\n", buf, cdev);
-- 
2.39.5




  reply	other threads:[~2025-02-16 15:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-16 15:07 [PATCH 1/2] cdev: merge identical partitions despite DEVFS_PARTITION_CAN_OVERLAP Ahmad Fatoum
2025-02-16 15:07 ` Ahmad Fatoum [this message]
2025-02-17  7:36 ` Sascha Hauer

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=20250216150718.2348520-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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