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

[MachO] Fix unaligned load in extractSections #68741

Merged
merged 2 commits into from
Oct 10, 2023

Conversation

thurstond
Copy link
Contributor

A recent change to ubsan
(7926744)
exposed an unaligned load in MachOReader (see
https://lab.llvm.org/buildbot/#/builders/85/builds/19482 for an example).

This patch fixes it by dropping the alignment.

A recent change to ubsan
(llvm@7926744)
exposed an unaligned load in MachOReader (see
https://lab.llvm.org/buildbot/#/builders/85/builds/19482 for an example).

This patch fixes it by dropping the alignment.
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 10, 2023

@llvm/pr-subscribers-llvm-binary-utilities

Author: Thurston Dang (thurstond)

Changes

A recent change to ubsan
(7926744)
exposed an unaligned load in MachOReader (see
https://lab.llvm.org/buildbot/#/builders/85/builds/19482 for an example).

This patch fixes it by dropping the alignment.


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

1 Files Affected:

  • (modified) llvm/lib/ObjCopy/MachO/MachOReader.cpp (+1-1)
diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
index 2cbffc12adbf765..9006f9e6d98d951 100644
--- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
@@ -67,7 +67,7 @@ Expected<std::vector<std::unique_ptr<Section>>> static extractSections(
                                                         LoadCmd.C.cmdsize);
        Curr < End; ++Curr) {
     SectionType Sec;
-    memcpy((void *)&Sec, Curr, sizeof(SectionType));
+    memcpy((void *)&Sec, reinterpret_cast<const char*>(Curr), sizeof(SectionType));
 
     if (MachOObj.isLittleEndian() != sys::IsLittleEndianHost)
       MachO::swapStruct(Sec);

@github-actions
Copy link

github-actions bot commented Oct 10, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

Please make the style change that the bot identified.

@thurstond
Copy link
Contributor Author

Please make the style change that the bot identified.

Done, thanks for the reminder!

@thurstond thurstond merged commit bfa7d10 into llvm:main Oct 10, 2023
2 of 3 checks passed
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.

None yet

3 participants