[PATCH 2/2] cmdlinepart: refuse partitions with empty name
Ahmad Fatoum
a.fatoum at pengutronix.de
Sun Feb 16 07:07:18 PST 2025
Running addpart /dev/mmc3 0xe0000 at 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 at 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
More information about the barebox
mailing list