diff options
Diffstat (limited to 'block/partitions')
-rw-r--r-- | block/partitions/cmdline.c | 49 | ||||
-rw-r--r-- | block/partitions/core.c | 11 | ||||
-rw-r--r-- | block/partitions/mac.c | 2 |
3 files changed, 39 insertions, 23 deletions
diff --git a/block/partitions/cmdline.c b/block/partitions/cmdline.c index 152c85df92..c03bc105e5 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); diff --git a/block/partitions/core.c b/block/partitions/core.c index eac887755f..37b5f92d07 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -419,21 +419,10 @@ static bool partition_overlaps(struct gendisk *disk, sector_t start, int bdev_add_partition(struct gendisk *disk, int partno, sector_t start, sector_t length) { - sector_t capacity = get_capacity(disk), end; struct block_device *part; int ret; mutex_lock(&disk->open_mutex); - if (check_add_overflow(start, length, &end)) { - ret = -EINVAL; - goto out; - } - - if (start >= capacity || end > capacity) { - ret = -EINVAL; - goto out; - } - if (!disk_live(disk)) { ret = -ENXIO; goto out; diff --git a/block/partitions/mac.c b/block/partitions/mac.c index 7b521df00a..c80183156d 100644 --- a/block/partitions/mac.c +++ b/block/partitions/mac.c @@ -20,6 +20,7 @@ extern void note_bootable_part(dev_t dev, int part, int goodness); * Code to understand MacOS partition tables. */ +#ifdef CONFIG_PPC_PMAC static inline void mac_fix_string(char *stg, int len) { int i; @@ -27,6 +28,7 @@ static inline void mac_fix_string(char *stg, int len) for (i = len - 1; i >= 0 && stg[i] == ' '; i--) stg[i] = 0; } +#endif int mac_partition(struct parsed_partitions *state) { |