stub: get_extra_dir() can return NULL
authorLennart Poettering <lennart@poettering.net>
Tue, 28 Nov 2023 20:21:37 +0000 (21:21 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 28 Nov 2023 23:53:30 +0000 (23:53 +0000)
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
src/boot/efi/stub.c

index f56db2e..5b90e17 100644 (file)
@@ -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)
index 572ea48..7ef3e76 100644 (file)
@@ -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,