summaryrefslogtreecommitdiffstats
path: root/block/partitions/cmdline.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 21:00:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 21:00:51 +0000
commit6d03a247468059b0e59c821ef39e6762d4d6fc30 (patch)
tree17b9c00de2c62e68c965c742cdbc206f77a375da /block/partitions/cmdline.c
parentReleasing progress-linux version 6.8.12-1~progress7.99u1. (diff)
downloadlinux-6d03a247468059b0e59c821ef39e6762d4d6fc30.tar.xz
linux-6d03a247468059b0e59c821ef39e6762d4d6fc30.zip
Merging upstream version 6.9.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'block/partitions/cmdline.c')
-rw-r--r--block/partitions/cmdline.c49
1 files changed, 37 insertions, 12 deletions
diff --git a/block/partitions/cmdline.c b/block/partitions/cmdline.c
index 152c85df9..c03bc105e 100644
--- a/block/partitions/cmdline.c
+++ b/block/partitions/cmdline.c
@@ -70,8 +70,8 @@ static int parse_subpart(struct cmdline_subpart **subpart, char *partdef)
}
if (*partdef == '(') {
- partdef++;
- char *next = strsep(&partdef, ")");
+ int length;
+ char *next = strchr(++partdef, ')');
if (!next) {
pr_warn("cmdline partition format is invalid.");
@@ -79,7 +79,11 @@ static int parse_subpart(struct cmdline_subpart **subpart, char *partdef)
goto fail;
}
- strscpy(new_subpart->name, next, sizeof(new_subpart->name));
+ length = min_t(int, next - partdef,
+ sizeof(new_subpart->name) - 1);
+ strscpy(new_subpart->name, partdef, length);
+
+ partdef = ++next;
} else
new_subpart->name[0] = '\0';
@@ -113,12 +117,14 @@ static void free_subpart(struct cmdline_parts *parts)
}
}
-static int parse_parts(struct cmdline_parts **parts, char *bdevdef)
+static int parse_parts(struct cmdline_parts **parts, const char *bdevdef)
{
int ret = -EINVAL;
char *next;
+ int length;
struct cmdline_subpart **next_subpart;
struct cmdline_parts *newparts;
+ char buf[BDEVNAME_SIZE + 32 + 4];
*parts = NULL;
@@ -126,19 +132,28 @@ static int parse_parts(struct cmdline_parts **parts, char *bdevdef)
if (!newparts)
return -ENOMEM;
- next = strsep(&bdevdef, ":");
+ next = strchr(bdevdef, ':');
if (!next) {
pr_warn("cmdline partition has no block device.");
goto fail;
}
- strscpy(newparts->name, next, sizeof(newparts->name));
+ length = min_t(int, next - bdevdef, sizeof(newparts->name) - 1);
+ strscpy(newparts->name, bdevdef, length);
newparts->nr_subparts = 0;
next_subpart = &newparts->subpart;
- while ((next = strsep(&bdevdef, ","))) {
- ret = parse_subpart(next_subpart, next);
+ while (next && *(++next)) {
+ bdevdef = next;
+ next = strchr(bdevdef, ',');
+
+ length = (!next) ? (sizeof(buf) - 1) :
+ min_t(int, next - bdevdef, sizeof(buf) - 1);
+
+ strscpy(buf, bdevdef, length);
+
+ ret = parse_subpart(next_subpart, buf);
if (ret)
goto fail;
@@ -184,17 +199,24 @@ static int cmdline_parts_parse(struct cmdline_parts **parts,
*parts = NULL;
- pbuf = buf = kstrdup(cmdline, GFP_KERNEL);
+ next = pbuf = buf = kstrdup(cmdline, GFP_KERNEL);
if (!buf)
return -ENOMEM;
next_parts = parts;
- while ((next = strsep(&pbuf, ";"))) {
- ret = parse_parts(next_parts, next);
+ while (next && *pbuf) {
+ next = strchr(pbuf, ';');
+ if (next)
+ *next = '\0';
+
+ ret = parse_parts(next_parts, pbuf);
if (ret)
goto fail;
+ if (next)
+ pbuf = ++next;
+
next_parts = &(*next_parts)->next_parts;
}
@@ -228,6 +250,7 @@ static struct cmdline_parts *bdev_parts;
static int add_part(int slot, struct cmdline_subpart *subpart,
struct parsed_partitions *state)
{
+ int label_min;
struct partition_meta_info *info;
char tmp[sizeof(info->volname) + 4];
@@ -239,7 +262,9 @@ static int add_part(int slot, struct cmdline_subpart *subpart,
info = &state->parts[slot].info;
- strscpy(info->volname, subpart->name, sizeof(info->volname));
+ label_min = min_t(int, sizeof(info->volname) - 1,
+ sizeof(subpart->name));
+ strscpy(info->volname, subpart->name, label_min);
snprintf(tmp, sizeof(tmp), "(%s)", info->volname);
strlcat(state->pp_buf, tmp, PAGE_SIZE);