fsutils/mkmbr/mkmbr.c: fix null pointer access when not all device space is defined in mbr
argv[argn] is accessed out of range when there are neither four partitions are specified nor the last partition is of auto size. Add a number of partition variable based on input argument number. Signed-off-by: Yinzhe Wu <Yinzhe.Wu@sony.com> Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com> Reviewed-by: Jacky Cao <Jacky.Cao@sony.com> Tested-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
This commit is contained in:
parent
57dd7fd03f
commit
aed7d2b8a9
@ -111,8 +111,10 @@ int main(int argc, FAR char *argv[])
|
|||||||
int argn;
|
int argn;
|
||||||
int fd;
|
int fd;
|
||||||
int ret;
|
int ret;
|
||||||
|
int nr_part;
|
||||||
|
|
||||||
if (argc < 4 || argc % 2 != 0)
|
nr_part = (argc - 2) / 2;
|
||||||
|
if (argc < 4 || argc % 2 != 0 || nr_part > 4)
|
||||||
{
|
{
|
||||||
print_usage();
|
print_usage();
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -133,7 +135,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
next = 1;
|
next = 1;
|
||||||
bsize = st.st_size / 512;
|
bsize = st.st_size / 512;
|
||||||
mbr_init(&mbr);
|
mbr_init(&mbr);
|
||||||
for (partn = 0; partn < 4 && next < bsize; partn++)
|
for (partn = 0; partn < nr_part && next < bsize; partn++)
|
||||||
{
|
{
|
||||||
argn = 2 * (partn + 1);
|
argn = 2 * (partn + 1);
|
||||||
if (!strcmp(argv[argn], "auto"))
|
if (!strcmp(argv[argn], "auto"))
|
||||||
|
Loading…
Reference in New Issue
Block a user