Skip to content

Commit

Permalink
fsutils/mkmbr/mkmbr.c: fix null pointer access when not all device sp…
Browse files Browse the repository at this point in the history
…ace 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 <[email protected]>
Reviewed-by: Yuezhang Mo <[email protected]>
Reviewed-by: Jacky Cao <[email protected]>
Tested-by: Yinzhe Wu <[email protected]>
  • Loading branch information
Windrow14 authored and xiaoxiang781216 committed Oct 9, 2024
1 parent 7cabf00 commit 6bebd1b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fsutils/mkmbr/mkmbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ int main(int argc, FAR char *argv[])
int argn;
int fd;
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();
return EINVAL;
Expand All @@ -133,7 +135,7 @@ int main(int argc, FAR char *argv[])
next = 1;
bsize = st.st_size / 512;
mbr_init(&mbr);
for (partn = 0; partn < 4 && next < bsize; partn++)
for (partn = 0; partn < nr_part && next < bsize; partn++)
{
argn = 2 * (partn + 1);
if (!strcmp(argv[argn], "auto"))
Expand Down

0 comments on commit 6bebd1b

Please sign in to comment.