Blame SOURCES/0478-gfxmenu-gui-Check-printf-format-in-the-gui_progress_.patch

9723a8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
9723a8
From: Thomas Frauendorfer | Miray Software <tf@miray.de>
9723a8
Date: Tue, 4 Aug 2020 13:49:51 +0200
9723a8
Subject: [PATCH] gfxmenu/gui: Check printf() format in the gui_progress_bar
9723a8
 and gui_label
9723a8
9723a8
The gui_progress_bar and gui_label components can display the timeout
9723a8
value. The format string can be set through a theme file. This patch
9723a8
adds a validation step to the format string.
9723a8
9723a8
If a user loads a theme file into the GRUB without this patch then
9723a8
a GUI label with the following settings
9723a8
9723a8
  + label {
9723a8
  ...
9723a8
  id = "__timeout__"
9723a8
  text = "%s"
9723a8
  }
9723a8
9723a8
will interpret the current timeout value as string pointer and print the
9723a8
memory at that position on the screen. It is not desired behavior.
9723a8
9723a8
Signed-off-by: Thomas Frauendorfer | Miray Software <tf@miray.de>
9723a8
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9723a8
---
9723a8
 grub-core/gfxmenu/gui_label.c        | 4 ++++
9723a8
 grub-core/gfxmenu/gui_progress_bar.c | 3 +++
9723a8
 2 files changed, 7 insertions(+)
9723a8
9723a8
diff --git a/grub-core/gfxmenu/gui_label.c b/grub-core/gfxmenu/gui_label.c
b71686
index a4c817891..1c190542a 100644
9723a8
--- a/grub-core/gfxmenu/gui_label.c
9723a8
+++ b/grub-core/gfxmenu/gui_label.c
9723a8
@@ -193,6 +193,10 @@ label_set_property (void *vself, const char *name, const char *value)
9723a8
 	   else if (grub_strcmp (value, "@KEYMAP_SHORT@") == 0)
9723a8
 	    value = _("enter: boot, `e': options, `c': cmd-line");
9723a8
 	   /* FIXME: Add more templates here if needed.  */
9723a8
+
9723a8
+	  if (grub_printf_fmt_check(value, "%d") != GRUB_ERR_NONE)
9723a8
+	    value = ""; /* Unsupported format. */
9723a8
+
9723a8
 	  self->template = grub_strdup (value);
9723a8
 	  self->text = grub_xasprintf (value, self->value);
9723a8
 	}
9723a8
diff --git a/grub-core/gfxmenu/gui_progress_bar.c b/grub-core/gfxmenu/gui_progress_bar.c
b71686
index b128f0866..ace85a125 100644
9723a8
--- a/grub-core/gfxmenu/gui_progress_bar.c
9723a8
+++ b/grub-core/gfxmenu/gui_progress_bar.c
9723a8
@@ -348,6 +348,9 @@ progress_bar_set_property (void *vself, const char *name, const char *value)
9723a8
 	   Please use the shortest form available in you language.  */
9723a8
 	value = _("%ds");
9723a8
 
9723a8
+      if (grub_printf_fmt_check(value, "%d") != GRUB_ERR_NONE)
9723a8
+	value = ""; /* Unsupported format. */
9723a8
+
9723a8
       self->template = grub_strdup (value);
9723a8
     }
9723a8
   else if (grub_strcmp (name, "font") == 0)