From: Lennart Poettering Date: Fri, 17 Sep 2021 08:48:46 +0000 (+0200) Subject: boot: add a way to indicate overflow in ALIGN_TO() X-Git-Tag: v250-rc1~629^2~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88657f757517bd0d5870c97acb1b88b59267ab1a;p=thirdparty%2Fsystemd.git boot: add a way to indicate overflow in ALIGN_TO() --- diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index a5b6435f1b6..2ee4f2b5180 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -8,8 +8,20 @@ #define OFFSETOF(x,y) __builtin_offsetof(x,y) +#define UINTN_MAX (~(UINTN)0) +#define INTN_MAX ((INTN)(UINTN_MAX>>1)) +#ifndef UINT32_MAX +#define UINT32_MAX ((UINT32) -1) +#endif +#ifndef UINT64_MAX +#define UINT64_MAX ((UINT64) -1) +#endif + static inline UINTN ALIGN_TO(UINTN l, UINTN ali) { - return ((l + ali - 1) & ~(ali - 1)); + if (l > UINTN_MAX - (ali - 1)) /* Overflow? */ + return UINTN_MAX; + + return ((l + (ali - 1)) & ~(ali - 1)); } EFI_STATUS parse_boolean(const CHAR8 *v, BOOLEAN *b); @@ -65,15 +77,6 @@ static inline void FileHandleClosep(EFI_FILE_HANDLE *handle) { &(const EFI_GUID) { 0x4a67b082, 0x0a4c, 0x41cf, { 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f } } #define EFI_GLOBAL_GUID &(const EFI_GUID) EFI_GLOBAL_VARIABLE -#define UINTN_MAX (~(UINTN)0) -#define INTN_MAX ((INTN)(UINTN_MAX>>1)) -#ifndef UINT32_MAX -#define UINT32_MAX ((UINT32) -1) -#endif -#ifndef UINT64_MAX -#define UINT64_MAX ((UINT64) -1) -#endif - VOID log_error_stall(const CHAR16 *fmt, ...); EFI_STATUS log_oom(void);