From ec43827bf746c0ccccdac6341f4288d2a622d492 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 28 Nov 2023 21:21:37 +0100 Subject: [PATCH] stub: get_extra_dir() can return NULL If we have a device path that is not the usual file system directory get_extra_dir() will return NULL. Handle that gracefully. Fixes: #30228 --- src/boot/efi/cpio.c | 5 ++++- src/boot/efi/stub.c | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/boot/efi/cpio.c b/src/boot/efi/cpio.c index f56db2e197f..5b90e17c41d 100644 --- a/src/boot/efi/cpio.c +++ b/src/boot/efi/cpio.c @@ -339,8 +339,11 @@ EFI_STATUS pack_cpio( if (err != EFI_SUCCESS) return log_error_status(err, "Unable to open root directory: %m"); - if (!dropin_dir) + if (!dropin_dir) { dropin_dir = rel_dropin_dir = get_extra_dir(loaded_image->FilePath); + if (!dropin_dir) + goto nothing; + } err = open_directory(root, dropin_dir, &extra_dir); if (err == EFI_NOT_FOUND) diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c index 572ea480f0e..7ef3e765446 100644 --- a/src/boot/efi/stub.c +++ b/src/boot/efi/stub.c @@ -556,8 +556,8 @@ static EFI_STATUS run(EFI_HANDLE image) { log_error_status(err, "Error loading global addons, ignoring: %m"); /* Some bootloaders always pass NULL in FilePath, so we need to check for it here. */ - if (loaded_image->FilePath) { - _cleanup_free_ char16_t *dropin_dir = get_extra_dir(loaded_image->FilePath); + _cleanup_free_ char16_t *dropin_dir = get_extra_dir(loaded_image->FilePath); + if (dropin_dir) { err = load_addons( image, loaded_image,