dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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