X Tutup
Skip to content

Commit 1462d24

Browse files
committed
efi: use assert_se() instead of assert() to guard for OOM issues in EFI code
1 parent 8890ec8 commit 1462d24

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/boot/efi/util.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@
2727
#define xnew_alloc(type, n, alloc) \
2828
({ \
2929
UINTN _alloc_size; \
30-
if (__builtin_mul_overflow(sizeof(type), (n), &_alloc_size)) \
31-
assert_not_reached(); \
30+
assert_se(!__builtin_mul_overflow(sizeof(type), (n), &_alloc_size)); \
3231
(type *) alloc(_alloc_size); \
3332
})
3433

35-
#define xallocate_pool(size) ASSERT_PTR(AllocatePool(size))
36-
#define xallocate_zero_pool(size) ASSERT_PTR(AllocateZeroPool(size))
37-
#define xreallocate_pool(p, old_size, new_size) ASSERT_PTR(ReallocatePool((p), (old_size), (new_size)))
38-
#define xpool_print(fmt, ...) ((CHAR16 *) ASSERT_PTR(PoolPrint((fmt), ##__VA_ARGS__)))
39-
#define xstrdup(str) ((CHAR16 *) ASSERT_PTR(StrDuplicate(str)))
34+
#define xallocate_pool(size) ASSERT_SE_PTR(AllocatePool(size))
35+
#define xallocate_zero_pool(size) ASSERT_SE_PTR(AllocateZeroPool(size))
36+
#define xreallocate_pool(p, old_size, new_size) ASSERT_SE_PTR(ReallocatePool((p), (old_size), (new_size)))
37+
#define xpool_print(fmt, ...) ((CHAR16 *) ASSERT_SE_PTR(PoolPrint((fmt), ##__VA_ARGS__)))
38+
#define xstrdup(str) ((CHAR16 *) ASSERT_SE_PTR(StrDuplicate(str)))
4039
#define xnew(type, n) xnew_alloc(type, (n), xallocate_pool)
4140
#define xnew0(type, n) xnew_alloc(type, (n), xallocate_zero_pool)
4241

src/boot/efi/xbootldr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static EFI_STATUS find_device(EFI_HANDLE *device, EFI_DEVICE_PATH **ret_device_p
226226
}
227227

228228
/* Patch in the data we found */
229-
EFI_DEVICE_PATH *xboot_path = ASSERT_PTR(DuplicateDevicePath(partition_path));
229+
EFI_DEVICE_PATH *xboot_path = ASSERT_SE_PTR(DuplicateDevicePath(partition_path));
230230
CopyMem((UINT8 *) xboot_path + ((UINT8 *) part_node - (UINT8 *) partition_path), &hd, sizeof(hd));
231231
*ret_device_path = xboot_path;
232232
return EFI_SUCCESS;

0 commit comments

Comments
 (0)
X Tutup