[libunwind] [libunwind] Undefined behaviour pointer arithmetic with null pointer (PR #98648)
Daniel Kiss via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 12 08:12:22 PDT 2024
https://github.com/DanielKristofKiss created https://github.com/llvm/llvm-project/pull/98648
Fixes #91144
>From 240add341b2c0a1be3d1ebf21938e70e51669126 Mon Sep 17 00:00:00 2001
From: Daniel Kiss <daniel.kiss at arm.com>
Date: Fri, 12 Jul 2024 15:56:40 +0200
Subject: [PATCH] [libunwind] Fix ubsan issue
---
libunwind/src/UnwindCursor.hpp | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 2ec60e4c123d5..01a61cea53ffa 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -230,8 +230,13 @@ void DwarfFDECache<A>::iterateCacheEntries(void (*func)(
}
#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
-
-#define arrayoffsetof(type, index, field) ((size_t)(&((type *)0)[index].field))
+template <typename TYPE, typename FIELD>
+__attribute__((no_sanitize("undefined"))) static inline size_t
+_arrayoffsetof(int index, FIELD TYPE::*field) {
+ return ((size_t)(&(((TYPE *)0)[index].*field)));
+}
+#define arrayoffsetof(type, index, field) \
+ _arrayoffsetof<struct type>(index, &type::field)
#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
template <typename A> class UnwindSectionHeader {
More information about the cfe-commits
mailing list