]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
efi: use assert_se() instead of assert() to guard for OOM issues in EFI code 22343/head
authorLennart Poettering <lennart@poettering.net>
Tue, 1 Feb 2022 14:28:33 +0000 (15:28 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 1 Feb 2022 14:31:20 +0000 (15:31 +0100)
src/boot/efi/util.h
src/boot/efi/xbootldr.c

index 40ce98c6110893150a7da32056732f27283f5dce..3d659f7043f96d62cd0689fc0cbec9c63db9268b 100644 (file)
 #define xnew_alloc(type, n, alloc)                                           \
         ({                                                                   \
                 UINTN _alloc_size;                                           \
-                if (__builtin_mul_overflow(sizeof(type), (n), &_alloc_size)) \
-                        assert_not_reached();                                \
+                assert_se(!__builtin_mul_overflow(sizeof(type), (n), &_alloc_size)); \
                 (type *) alloc(_alloc_size);                                 \
         })
 
-#define xallocate_pool(size) ASSERT_PTR(AllocatePool(size))
-#define xallocate_zero_pool(size) ASSERT_PTR(AllocateZeroPool(size))
-#define xreallocate_pool(p, old_size, new_size) ASSERT_PTR(ReallocatePool((p), (old_size), (new_size)))
-#define xpool_print(fmt, ...) ((CHAR16 *) ASSERT_PTR(PoolPrint((fmt), ##__VA_ARGS__)))
-#define xstrdup(str) ((CHAR16 *) ASSERT_PTR(StrDuplicate(str)))
+#define xallocate_pool(size) ASSERT_SE_PTR(AllocatePool(size))
+#define xallocate_zero_pool(size) ASSERT_SE_PTR(AllocateZeroPool(size))
+#define xreallocate_pool(p, old_size, new_size) ASSERT_SE_PTR(ReallocatePool((p), (old_size), (new_size)))
+#define xpool_print(fmt, ...) ((CHAR16 *) ASSERT_SE_PTR(PoolPrint((fmt), ##__VA_ARGS__)))
+#define xstrdup(str) ((CHAR16 *) ASSERT_SE_PTR(StrDuplicate(str)))
 #define xnew(type, n) xnew_alloc(type, (n), xallocate_pool)
 #define xnew0(type, n) xnew_alloc(type, (n), xallocate_zero_pool)
 
index 49d5707e02f40ebee8366ab7fac87c6d0c309489..6fa7e49e5de64f15b5c4cd2201768466a7fb5057 100644 (file)
@@ -226,7 +226,7 @@ static EFI_STATUS find_device(EFI_HANDLE *device, EFI_DEVICE_PATH **ret_device_p
                 }
 
                 /* Patch in the data we found */
-                EFI_DEVICE_PATH *xboot_path = ASSERT_PTR(DuplicateDevicePath(partition_path));
+                EFI_DEVICE_PATH *xboot_path = ASSERT_SE_PTR(DuplicateDevicePath(partition_path));
                 CopyMem((UINT8 *) xboot_path + ((UINT8 *) part_node - (UINT8 *) partition_path), &hd, sizeof(hd));
                 *ret_device_path = xboot_path;
                 return EFI_SUCCESS;