Skip to content

Commit 6bebd1b

Browse files
Windrow14xiaoxiang781216
authored andcommitted
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>
1 parent 7cabf00 commit 6bebd1b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fsutils/mkmbr/mkmbr.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ int main(int argc, FAR char *argv[])
111111
int argn;
112112
int fd;
113113
int ret;
114+
int nr_part;
114115

115-
if (argc < 4 || argc % 2 != 0)
116+
nr_part = (argc - 2) / 2;
117+
if (argc < 4 || argc % 2 != 0 || nr_part > 4)
116118
{
117119
print_usage();
118120
return EINVAL;
@@ -133,7 +135,7 @@ int main(int argc, FAR char *argv[])
133135
next = 1;
134136
bsize = st.st_size / 512;
135137
mbr_init(&mbr);
136-
for (partn = 0; partn < 4 && next < bsize; partn++)
138+
for (partn = 0; partn < nr_part && next < bsize; partn++)
137139
{
138140
argn = 2 * (partn + 1);
139141
if (!strcmp(argv[argn], "auto"))

0 commit comments

Comments
 (0)