This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 6bebd1bea fsutils/mkmbr/mkmbr.c: fix null pointer access when not all
device space is defined in mbr
6bebd1bea is described below
commit 6bebd1bea1b95ec52ac09f039996949fe158a223
Author: Windrow14 <[email protected]>
AuthorDate: Wed Oct 9 13:29:38 2024 +0800
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 <[email protected]>
Reviewed-by: Yuezhang Mo <[email protected]>
Reviewed-by: Jacky Cao <[email protected]>
Tested-by: Yinzhe Wu <[email protected]>
---
fsutils/mkmbr/mkmbr.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fsutils/mkmbr/mkmbr.c b/fsutils/mkmbr/mkmbr.c
index 9c0251233..4c468c5cf 100644
--- a/fsutils/mkmbr/mkmbr.c
+++ b/fsutils/mkmbr/mkmbr.c
@@ -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;
@@ -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"))