]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
mm: Temporarily disable grub_mm_debug while calling grub_vprintf() in grub_printf()
authorGlenn Washburn <development@efficientek.com>
Tue, 15 Feb 2022 18:36:43 +0000 (12:36 -0600)
committerDaniel Kiper <daniel.kiper@oracle.com>
Mon, 7 Mar 2022 14:26:21 +0000 (15:26 +0100)
To prevent infinite recursion when grub_mm_debug is on, disable it when
calling grub_vprintf(). One such call loop is:
  grub_vprintf() -> parse_printf_args() -> parse_printf_arg_fmt() ->
    grub_debug_calloc() -> grub_printf() -> grub_vprintf().

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/kern/misc.c

index de40f566d6f696b35ee9940583275ae7d01d283e..18bde5d506963a6639fca0c7b442834eaffa6cf1 100644 (file)
@@ -113,10 +113,30 @@ grub_printf (const char *fmt, ...)
   va_list ap;
   int ret;
 
+#if defined(MM_DEBUG) && !defined(GRUB_UTIL) && !defined (GRUB_MACHINE_EMU)
+  /*
+   * To prevent infinite recursion when grub_mm_debug is on, disable it
+   * when calling grub_vprintf(). One such call loop is:
+   *   grub_vprintf() -> parse_printf_args() -> parse_printf_arg_fmt() ->
+   *     grub_debug_calloc() -> grub_printf() -> grub_vprintf().
+   */
+  int grub_mm_debug_save = 0;
+
+  if (grub_mm_debug)
+    {
+      grub_mm_debug_save = grub_mm_debug;
+      grub_mm_debug = 0;
+    }
+#endif
+
   va_start (ap, fmt);
   ret = grub_vprintf (fmt, ap);
   va_end (ap);
 
+#if defined(MM_DEBUG) && !defined(GRUB_UTIL) && !defined (GRUB_MACHINE_EMU)
+  grub_mm_debug = grub_mm_debug_save;
+#endif
+
   return ret;
 }