From 0a94ba73e8b3b0bb28ad2650204c47571894d849 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Tue, 23 Jul 2024 17:36:51 -0400 Subject: [PATCH 1/8] i.ortho.photo: Fix uninitialized variable issue in menu.c --- imagery/i.ortho.photo/i.ortho.photo/menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imagery/i.ortho.photo/i.ortho.photo/menu.c b/imagery/i.ortho.photo/i.ortho.photo/menu.c index 76bfe6a3f04..c2471d4abe2 100644 --- a/imagery/i.ortho.photo/i.ortho.photo/menu.c +++ b/imagery/i.ortho.photo/i.ortho.photo/menu.c @@ -33,7 +33,7 @@ int main(int argc, char **argv) char *desc_ortho_opt; char *moduletorun; const char *grname; - char tosystem[99]; + char tosystem[99] = ""; /* initialize grass */ G_gisinit(argv[0]); From 721430ec6543a50109de9e9e8438327bdd7b8c05 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Wed, 24 Jul 2024 13:28:18 -0400 Subject: [PATCH 2/8] strncpy changes updated --- imagery/i.ortho.photo/i.ortho.photo/menu.c | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/imagery/i.ortho.photo/i.ortho.photo/menu.c b/imagery/i.ortho.photo/i.ortho.photo/menu.c index c2471d4abe2..44556694399 100644 --- a/imagery/i.ortho.photo/i.ortho.photo/menu.c +++ b/imagery/i.ortho.photo/i.ortho.photo/menu.c @@ -24,6 +24,8 @@ #include #include "orthophoto.h" +#define BUFFER_SIZE 99 + int main(int argc, char **argv) { char *p; @@ -33,7 +35,7 @@ int main(int argc, char **argv) char *desc_ortho_opt; char *moduletorun; const char *grname; - char tosystem[99] = ""; + char tosystem[BUFFER_SIZE] = ""; /* initialize grass */ G_gisinit(argv[0]); @@ -82,8 +84,8 @@ int main(int argc, char **argv) /* group validity check */ /*----------------------*/ - strncpy(group.name, group_opt->answer, 99); - group.name[99] = '\0'; + strncpy(group.name, group_opt->answer, BUFFER_SIZE); + group.name[BUFFER_SIZE - 1] = '\0'; /* strip off mapset if it's there: I_() fns only work with current mapset */ if ((p = strchr(group.name, '@'))) *p = 0; @@ -96,26 +98,30 @@ int main(int argc, char **argv) moduletorun = ortho_opt->answer; /* run the program chosen */ if (strcmp(moduletorun, "g.gui.photo2image") == 0) { - strcpy(tosystem, "g.gui.photo2image"); + strncpy(tosystem, "g.gui.photo2image", BUFFER_SIZE - 1); + tosystem[BUFFER_SIZE - 1] = '\0'; return system((const char *)tosystem); } else if (strcmp(moduletorun, "g.gui.image2target") == 0) { - strcpy(tosystem, "g.gui.image2target"); + strncpy(tosystem, "g.gui.image2target", BUFFER_SIZE - 1); + tosystem[BUFFER_SIZE - 1] = '\0'; return system((const char *)tosystem); } else { if (strcmp(moduletorun, "i.group") == 0) - strcpy(tosystem, "i.group --ui group="); + strncpy(tosystem, "i.group --ui group=", BUFFER_SIZE - 1); if (strcmp(moduletorun, "i.ortho.target") == 0) - strcpy(tosystem, "i.ortho.target --ui group="); + strncpy(tosystem, "i.ortho.target --ui group=", BUFFER_SIZE - 1); if (strcmp(moduletorun, "i.ortho.elev") == 0) - strcpy(tosystem, "i.ortho.elev --ui group="); + strncpy(tosystem, "i.ortho.elev --ui group=", BUFFER_SIZE - 1); if (strcmp(moduletorun, "i.ortho.camera") == 0) - strcpy(tosystem, "i.ortho.camera --ui group="); + strncpy(tosystem, "i.ortho.camera --ui group=", BUFFER_SIZE - 1); if (strcmp(moduletorun, "i.ortho.init") == 0) - strcpy(tosystem, "i.ortho.init --ui group="); + strncpy(tosystem, "i.ortho.init --ui group=", BUFFER_SIZE - 1); if (strcmp(moduletorun, "i.ortho.rectify") == 0) - strcpy(tosystem, "i.ortho.rectify --ui group="); + strncpy(tosystem, "i.ortho.rectify --ui group=", BUFFER_SIZE - 1); + + tosystem[BUFFER_SIZE - 1] = '\0'; strcat(tosystem, grname); return system((const char *)tosystem); } From 298ea6226791b451b95bbd0760ab53606e3ceaaf Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Tue, 30 Jul 2024 15:36:16 -0400 Subject: [PATCH 3/8] use G_strlcpy --- imagery/i.ortho.photo/i.ortho.photo/menu.c | 23 +++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/imagery/i.ortho.photo/i.ortho.photo/menu.c b/imagery/i.ortho.photo/i.ortho.photo/menu.c index 44556694399..0d7a8382373 100644 --- a/imagery/i.ortho.photo/i.ortho.photo/menu.c +++ b/imagery/i.ortho.photo/i.ortho.photo/menu.c @@ -84,8 +84,7 @@ int main(int argc, char **argv) /* group validity check */ /*----------------------*/ - strncpy(group.name, group_opt->answer, BUFFER_SIZE); - group.name[BUFFER_SIZE - 1] = '\0'; + G_strlcpy(group.name, group_opt->answer, BUFFER_SIZE); /* strip off mapset if it's there: I_() fns only work with current mapset */ if ((p = strchr(group.name, '@'))) *p = 0; @@ -98,30 +97,26 @@ int main(int argc, char **argv) moduletorun = ortho_opt->answer; /* run the program chosen */ if (strcmp(moduletorun, "g.gui.photo2image") == 0) { - strncpy(tosystem, "g.gui.photo2image", BUFFER_SIZE - 1); - tosystem[BUFFER_SIZE - 1] = '\0'; + G_strlcpy(tosystem, "g.gui.photo2image", BUFFER_SIZE); return system((const char *)tosystem); } else if (strcmp(moduletorun, "g.gui.image2target") == 0) { - strncpy(tosystem, "g.gui.image2target", BUFFER_SIZE - 1); - tosystem[BUFFER_SIZE - 1] = '\0'; + G_strlcpy(tosystem, "g.gui.image2target", BUFFER_SIZE); return system((const char *)tosystem); } else { if (strcmp(moduletorun, "i.group") == 0) - strncpy(tosystem, "i.group --ui group=", BUFFER_SIZE - 1); + G_strlcpy(tosystem, "i.group --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.target") == 0) - strncpy(tosystem, "i.ortho.target --ui group=", BUFFER_SIZE - 1); + G_strlcpy(tosystem, "i.ortho.target --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.elev") == 0) - strncpy(tosystem, "i.ortho.elev --ui group=", BUFFER_SIZE - 1); + G_strlcpy(tosystem, "i.ortho.elev --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.camera") == 0) - strncpy(tosystem, "i.ortho.camera --ui group=", BUFFER_SIZE - 1); + G_strlcpy(tosystem, "i.ortho.camera --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.init") == 0) - strncpy(tosystem, "i.ortho.init --ui group=", BUFFER_SIZE - 1); + G_strlcpy(tosystem, "i.ortho.init --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.rectify") == 0) - strncpy(tosystem, "i.ortho.rectify --ui group=", BUFFER_SIZE - 1); - - tosystem[BUFFER_SIZE - 1] = '\0'; + G_strlcpy(tosystem, "i.ortho.rectify --ui group=", BUFFER_SIZE); strcat(tosystem, grname); return system((const char *)tosystem); } From 39b757861ac77fdcaacbc60de64d6a11486b55c7 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Thu, 1 Aug 2024 19:59:36 -0400 Subject: [PATCH 4/8] requested changes --- imagery/i.ortho.photo/i.ortho.photo/menu.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/imagery/i.ortho.photo/i.ortho.photo/menu.c b/imagery/i.ortho.photo/i.ortho.photo/menu.c index 0d7a8382373..dac96fafca8 100644 --- a/imagery/i.ortho.photo/i.ortho.photo/menu.c +++ b/imagery/i.ortho.photo/i.ortho.photo/menu.c @@ -36,6 +36,7 @@ int main(int argc, char **argv) char *moduletorun; const char *grname; char tosystem[BUFFER_SIZE] = ""; + size_t len; /* initialize grass */ G_gisinit(argv[0]); @@ -84,7 +85,10 @@ int main(int argc, char **argv) /* group validity check */ /*----------------------*/ - G_strlcpy(group.name, group_opt->answer, BUFFER_SIZE); + len = G_strlcpy(group.name, group_opt->answer, BUFFER_SIZE); + if (len >= BUFFER_SIZE) { + G_fatal_error(_("Name <%s> is too long"), group_opt->answer); + } /* strip off mapset if it's there: I_() fns only work with current mapset */ if ((p = strchr(group.name, '@'))) *p = 0; @@ -97,26 +101,26 @@ int main(int argc, char **argv) moduletorun = ortho_opt->answer; /* run the program chosen */ if (strcmp(moduletorun, "g.gui.photo2image") == 0) { - G_strlcpy(tosystem, "g.gui.photo2image", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "g.gui.photo2image", BUFFER_SIZE); return system((const char *)tosystem); } else if (strcmp(moduletorun, "g.gui.image2target") == 0) { - G_strlcpy(tosystem, "g.gui.image2target", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "g.gui.image2target", BUFFER_SIZE); return system((const char *)tosystem); } else { if (strcmp(moduletorun, "i.group") == 0) - G_strlcpy(tosystem, "i.group --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "i.group --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.target") == 0) - G_strlcpy(tosystem, "i.ortho.target --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "i.ortho.target --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.elev") == 0) - G_strlcpy(tosystem, "i.ortho.elev --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "i.ortho.elev --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.camera") == 0) - G_strlcpy(tosystem, "i.ortho.camera --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "i.ortho.camera --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.init") == 0) - G_strlcpy(tosystem, "i.ortho.init --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "i.ortho.init --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.rectify") == 0) - G_strlcpy(tosystem, "i.ortho.rectify --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "i.ortho.rectify --ui group=", BUFFER_SIZE); strcat(tosystem, grname); return system((const char *)tosystem); } From be6a2114a3f0f1eac41797f8cbf00d7fd8099b2f Mon Sep 17 00:00:00 2001 From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com> Date: Thu, 1 Aug 2024 20:01:10 -0400 Subject: [PATCH 5/8] Update imagery/i.ortho.photo/i.ortho.photo/menu.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- imagery/i.ortho.photo/i.ortho.photo/menu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imagery/i.ortho.photo/i.ortho.photo/menu.c b/imagery/i.ortho.photo/i.ortho.photo/menu.c index dac96fafca8..8080936e9ee 100644 --- a/imagery/i.ortho.photo/i.ortho.photo/menu.c +++ b/imagery/i.ortho.photo/i.ortho.photo/menu.c @@ -112,7 +112,8 @@ int main(int argc, char **argv) if (strcmp(moduletorun, "i.group") == 0) (void)G_strlcpy(tosystem, "i.group --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.target") == 0) - (void)G_strlcpy(tosystem, "i.ortho.target --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, + "i.ortho.target --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.elev") == 0) (void)G_strlcpy(tosystem, "i.ortho.elev --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.camera") == 0) From da77cb3e609edfb2fd3ab5b7db04a4eff04ad24e Mon Sep 17 00:00:00 2001 From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com> Date: Thu, 1 Aug 2024 20:01:29 -0400 Subject: [PATCH 6/8] Update imagery/i.ortho.photo/i.ortho.photo/menu.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- imagery/i.ortho.photo/i.ortho.photo/menu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imagery/i.ortho.photo/i.ortho.photo/menu.c b/imagery/i.ortho.photo/i.ortho.photo/menu.c index 8080936e9ee..ac717b3a59e 100644 --- a/imagery/i.ortho.photo/i.ortho.photo/menu.c +++ b/imagery/i.ortho.photo/i.ortho.photo/menu.c @@ -117,7 +117,8 @@ int main(int argc, char **argv) if (strcmp(moduletorun, "i.ortho.elev") == 0) (void)G_strlcpy(tosystem, "i.ortho.elev --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.camera") == 0) - (void)G_strlcpy(tosystem, "i.ortho.camera --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, + "i.ortho.camera --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.init") == 0) (void)G_strlcpy(tosystem, "i.ortho.init --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.rectify") == 0) From a2eb82efcc30614c1f488452525990628f2706af Mon Sep 17 00:00:00 2001 From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com> Date: Thu, 1 Aug 2024 20:01:36 -0400 Subject: [PATCH 7/8] Update imagery/i.ortho.photo/i.ortho.photo/menu.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- imagery/i.ortho.photo/i.ortho.photo/menu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imagery/i.ortho.photo/i.ortho.photo/menu.c b/imagery/i.ortho.photo/i.ortho.photo/menu.c index ac717b3a59e..0902f8a101b 100644 --- a/imagery/i.ortho.photo/i.ortho.photo/menu.c +++ b/imagery/i.ortho.photo/i.ortho.photo/menu.c @@ -122,7 +122,8 @@ int main(int argc, char **argv) if (strcmp(moduletorun, "i.ortho.init") == 0) (void)G_strlcpy(tosystem, "i.ortho.init --ui group=", BUFFER_SIZE); if (strcmp(moduletorun, "i.ortho.rectify") == 0) - (void)G_strlcpy(tosystem, "i.ortho.rectify --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, + "i.ortho.rectify --ui group=", BUFFER_SIZE); strcat(tosystem, grname); return system((const char *)tosystem); } From 89e2c6cdbbc40662621cde19baec0ab0b5800dd6 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Thu, 1 Aug 2024 20:06:46 -0400 Subject: [PATCH 8/8] requested changes --- imagery/i.ortho.photo/i.ortho.photo/menu.c | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/imagery/i.ortho.photo/i.ortho.photo/menu.c b/imagery/i.ortho.photo/i.ortho.photo/menu.c index dac96fafca8..40313c6c891 100644 --- a/imagery/i.ortho.photo/i.ortho.photo/menu.c +++ b/imagery/i.ortho.photo/i.ortho.photo/menu.c @@ -24,7 +24,7 @@ #include #include "orthophoto.h" -#define BUFFER_SIZE 99 +#define BUF_SIZE 99 int main(int argc, char **argv) { @@ -35,7 +35,7 @@ int main(int argc, char **argv) char *desc_ortho_opt; char *moduletorun; const char *grname; - char tosystem[BUFFER_SIZE] = ""; + char tosystem[BUF_SIZE] = ""; size_t len; /* initialize grass */ @@ -85,8 +85,8 @@ int main(int argc, char **argv) /* group validity check */ /*----------------------*/ - len = G_strlcpy(group.name, group_opt->answer, BUFFER_SIZE); - if (len >= BUFFER_SIZE) { + len = G_strlcpy(group.name, group_opt->answer, BUF_SIZE); + if (len >= BUF_SIZE) { G_fatal_error(_("Name <%s> is too long"), group_opt->answer); } /* strip off mapset if it's there: I_() fns only work with current mapset */ @@ -101,26 +101,26 @@ int main(int argc, char **argv) moduletorun = ortho_opt->answer; /* run the program chosen */ if (strcmp(moduletorun, "g.gui.photo2image") == 0) { - (void)G_strlcpy(tosystem, "g.gui.photo2image", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "g.gui.photo2image", BUF_SIZE); return system((const char *)tosystem); } else if (strcmp(moduletorun, "g.gui.image2target") == 0) { - (void)G_strlcpy(tosystem, "g.gui.image2target", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "g.gui.image2target", BUF_SIZE); return system((const char *)tosystem); } else { if (strcmp(moduletorun, "i.group") == 0) - (void)G_strlcpy(tosystem, "i.group --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "i.group --ui group=", BUF_SIZE); if (strcmp(moduletorun, "i.ortho.target") == 0) - (void)G_strlcpy(tosystem, "i.ortho.target --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "i.ortho.target --ui group=", BUF_SIZE); if (strcmp(moduletorun, "i.ortho.elev") == 0) - (void)G_strlcpy(tosystem, "i.ortho.elev --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "i.ortho.elev --ui group=", BUF_SIZE); if (strcmp(moduletorun, "i.ortho.camera") == 0) - (void)G_strlcpy(tosystem, "i.ortho.camera --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "i.ortho.camera --ui group=", BUF_SIZE); if (strcmp(moduletorun, "i.ortho.init") == 0) - (void)G_strlcpy(tosystem, "i.ortho.init --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "i.ortho.init --ui group=", BUF_SIZE); if (strcmp(moduletorun, "i.ortho.rectify") == 0) - (void)G_strlcpy(tosystem, "i.ortho.rectify --ui group=", BUFFER_SIZE); + (void)G_strlcpy(tosystem, "i.ortho.rectify --ui group=", BUF_SIZE); strcat(tosystem, grname); return system((const char *)tosystem); }