Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libunwind] Undefined behaviour pointer arithmetic with null pointer #98648

Merged
merged 3 commits into from
Aug 5, 2024

Conversation

DanielKristofKiss
Copy link
Member

Fixes #91144

@DanielKristofKiss DanielKristofKiss marked this pull request as ready for review July 19, 2024 14:08
@DanielKristofKiss DanielKristofKiss requested a review from a team as a code owner July 19, 2024 14:08
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 19, 2024

@llvm/pr-subscribers-libunwind

Author: Daniel Kiss (DanielKristofKiss)

Changes

Fixes #91144


Full diff: https://github.com/llvm/llvm-project/pull/98648.diff

1 Files Affected:

  • (modified) libunwind/src/UnwindCursor.hpp (+2-2)
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 2ec60e4c123d5..1fa95b4ebee19 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -230,8 +230,8 @@ void DwarfFDECache<A>::iterateCacheEntries(void (*func)(
 }
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 
-
-#define arrayoffsetof(type, index, field) ((size_t)(&((type *)0)[index].field))
+#define arrayoffsetof(type, index, field)                                      \
+  (sizeof(type) * (index) + offsetof(type, field))
 
 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
 template <typename A> class UnwindSectionHeader {

Copy link
Member

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct to me.

@DanielKristofKiss DanielKristofKiss merged commit 710590e into llvm:main Aug 5, 2024
59 checks passed
banach-space pushed a commit to banach-space/llvm-project that referenced this pull request Aug 7, 2024
kstoimenov pushed a commit to kstoimenov/llvm-project that referenced this pull request Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libunwind] Undefined behavior pointer arithmetic with null pointer
4 participants