dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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