Skip to contentSkip to conversation

util/grub-mkrescue: Check existence of option arguments

PATCH In review Thomas Schmitt via Grub-devel 2 participants 2 messages Jun 17, 2024 – Jun 19, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 util/grub-mkrescue: Check existence of option arguments

As reported by Victoriia Egorova in bug 65880, grub-mkrescue does not verify that the expected argument of an option like -d or -k does really exist in argv.
So check the loop counter before incrementing it inside the loop which copies argv to argp_argv. Issue an error message similar to what older versions of grub-mkrescue did with a missing argument (e.g 2.02).

---
 util/grub-mkrescue.c | 6 ++++++
 1 file changed, 6 insertions(+)
util/grub-mkrescue.c +6 -0
index abcc1c2f5..8714d819e 100644
@@ -477,6 +477,9 @@ main (int argc, char *argv[])
     for (i = 1; i < argc; i++)
       {
 	if (strcmp (argv[i], "-output") == 0) {
+	  if (i + 1 >= argc)
+	    grub_util_error ("%s -- '%s'", _("option requires an argument"),
+	                     argv[i]);
 	  argp_argv[argp_argc++] = (char *) "--output";
 	  i++;
 	  argp_argv[argp_argc++] = argv[i];
@@ -485,6 +488,9 @@ main (int argc, char *argv[])
 	switch (args_to_eat (argv[i]))
 	  {
 	  case 2:
+	    if (i + 1 >= argc)
+	      grub_util_error ("%s -- '%s'", _("option requires an argument"),
+	                       argv[i]);
 	    argp_argv[argp_argc++] = argv[i++];
 	    /* Fallthrough  */
 	  case 1:

--
2.39.2

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Thomas Schmitt via Grub-devel

As reported by Victoriia Egorova in bug 65880, grub-mkrescue does not verify that the expected argument of an option like -d or -k does really exist in argv.
So check the loop counter before incrementing it inside the loop which copies argv to argp_argv. Issue an error message similar to what older versions of grub-mkrescue did with a missing argument (e.g 2.02).

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel