]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: add a way to indicate overflow in ALIGN_TO()
authorLennart Poettering <lennart@poettering.net>
Fri, 17 Sep 2021 08:48:46 +0000 (10:48 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 23 Sep 2021 15:10:21 +0000 (17:10 +0200)
src/boot/efi/util.h

index a5b6435f1b685c242fa40dc3bb1148384c2f6b8f..2ee4f2b51804f77688328cbff6aaee3fd1e864cc 100644 (file)
@@ -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);