From: Michael Chang Date: Mon, 19 Feb 2024 03:29:11 +0000 (+0800) Subject: gfxmenu/view: Resolve false grub_errno disrupting boot process X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39c927df66c7ca62d97905d1385054ac9ce67209;p=thirdparty%2Fgrub.git gfxmenu/view: Resolve false grub_errno disrupting boot process When enabling gfxmenu and choosing to boot the Xen hypervisor from its menu, an error occurred: error: ../../grub-core/video/bitmap_scale.c:42:null src bitmap in grub_video_create_scaled. The error is returned by grub_video_bitmap_create_scaled() when the source pixmap is not there. The init_background() uses it to scale up the background image so it can fully fit into the screen resolution. However not all backgrounds are set by a image, i.e. the "desktop-image" property of the theme file. Instead a color code may be used, for example OpenSUSE's green background uses "desktop-color" property: desktop-color: "#0D202F" So it is absolutely fine to call init_background() without a raw pixmap if color code is used. A missing check has to be added to ensure the grub_errno will not be erroneously set and gets in the way of ensuing boot process. The reason it happens sporadically is due to grub_errno is reset to GRUB_ERR_NONE in other places if a function's error return can be ignored. In particular this hunk in grub_gfxmenu_create_box() does the majority of the reset of grub_errno returned by init_background(), but the path may not be always chosen. grub_video_bitmap_load (&box->raw_pixmaps[i], path); grub_free (path); /* Ignore missing pixmaps. */ grub_errno = GRUB_ERR_NONE; In any case, we cannot account on such random behavior and should only return grub_errno if it is justified. On the occasion move the grub_video_bitmap struct definition to the beginning of the function. Signed-off-by: Michael Chang Reviewed-by: Daniel Kiper --- diff --git a/grub-core/gfxmenu/view.c b/grub-core/gfxmenu/view.c index 6358004b2..e02eba8b0 100644 --- a/grub-core/gfxmenu/view.c +++ b/grub-core/gfxmenu/view.c @@ -553,10 +553,18 @@ init_terminal (grub_gfxmenu_view_t view) static void init_background (grub_gfxmenu_view_t view) { + struct grub_video_bitmap *scaled_bitmap; + + /* + * You don't have to scale a raw image if it's not present. This prevents + * setting grub_errno and disrupting a command execution. + */ + if (view->raw_desktop_image == NULL) + return; + if (view->scaled_desktop_image) return; - struct grub_video_bitmap *scaled_bitmap; if (view->desktop_image_scale_method == GRUB_VIDEO_BITMAP_SELECTION_METHOD_STRETCH) grub_video_bitmap_create_scaled (&scaled_bitmap,