-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lld][macho] Fix segfault while processing malformed object file. #167025
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
Conversation
|
@llvm/pr-subscribers-lld-macho Author: Prabhu Rajasekaran (Prabhuk) ChangesFull diff: https://github.com/llvm/llvm-project/pull/167025.diff 1 Files Affected:
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 20e4a1d755229..add59272d9f67 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -808,6 +808,11 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section> sectionHeaders,
continue;
if ((sym.n_type & N_TYPE) == N_SECT) {
+ if (sym.n_sect == 0) {
+ error("Section symbol " + StringRef(strtab + sym.n_strx) + " in " +
+ toString(this) + " has an invalid section index of 0");
+ llvm_unreachable("Section symbol without an associated section.");
+ }
Subsections &subsections = sections[sym.n_sect - 1]->subsections;
// parseSections() may have chosen not to parse this section.
if (subsections.empty())
|
|
@llvm/pr-subscribers-lld Author: Prabhu Rajasekaran (Prabhuk) ChangesFull diff: https://github.com/llvm/llvm-project/pull/167025.diff 1 Files Affected:
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 20e4a1d755229..add59272d9f67 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -808,6 +808,11 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section> sectionHeaders,
continue;
if ((sym.n_type & N_TYPE) == N_SECT) {
+ if (sym.n_sect == 0) {
+ error("Section symbol " + StringRef(strtab + sym.n_strx) + " in " +
+ toString(this) + " has an invalid section index of 0");
+ llvm_unreachable("Section symbol without an associated section.");
+ }
Subsections &subsections = sections[sym.n_sect - 1]->subsections;
// parseSections() may have chosen not to parse this section.
if (subsections.empty())
|
|
Trying to add a test by generating a yaml file from the malformed object file that led to the segfault. |
Co-authored-by: Ellis Hoag <ellis.sparky.hoag@gmail.com>
mysterymath
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Ran into a use case where we had a MachO object file with a section symbol which did not have a section associated with it segfaults during linking. This patch aims to handle such cases gracefully and avoid the linker from crashing.