@@ -79,8 +79,8 @@ static int parse_subpart(struct cmdline_subpart **subpart, char *partdef)Shouldn't that be a memcpy() with the original length?
goto fail;
}
- length = min_t(int, next - partdef,
- sizeof(new_subpart->name) - 1);
+ length = min_t(int, next - partdef + 1,
+ sizeof(new_subpart->name));
strscpy(new_subpart->name, partdef, length);
Since it looks as though there is something equivalent to:
next = strchr(partdef, ',');
just above?
Maybe with:
new_subpart->name[length] = '\0';
if the target isn't zero filled (which the strncpy() probably
relied on.)
@@ -262,7 +262,7 @@ static int add_part(int slot, struct cmdline_subpart *subpart,WTF?
info = &state->parts[slot].info;
- label_min = min_t(int, sizeof(info->volname) - 1,
+ label_min = min_t(int, sizeof(info->volname),
sizeof(subpart->name));
strscpy(info->volname, subpart->name, label_min);
That only makes any sense if subpart->name might not be '\0'
terminated - which strncpy() would have handled fine (with the -1).
Otherwise what is wrong with:
strscpy(info->volname, subpart->name, sizeof (info->volname));
David