Skip to content

[lldb] Don't crash on malformed filesets #98388

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

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

JDevlieghere
Copy link
Member

The memory read can fail for a malformed fileset. Handle it gracefully instead of passing a nullptr to the std::string constructor.

rdar://131477833

The memory read can fail for a malformed fileset. Handle it gracefully
instead of passing a nullptr to the std::string constructor.

rdar://131477833
@llvmbot
Copy link
Member

llvmbot commented Jul 10, 2024

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

The memory read can fail for a malformed fileset. Handle it gracefully instead of passing a nullptr to the std::string constructor.

rdar://131477833


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

1 Files Affected:

  • (modified) lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp (+3-3)
diff --git a/lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp b/lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp
index 2dc71d85777ca..76141f7976413 100644
--- a/lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp
+++ b/lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp
@@ -159,9 +159,9 @@ ParseFileset(DataExtractor &data, mach_header header,
       fileset_entry_command entry;
       data.CopyData(load_cmd_offset, sizeof(fileset_entry_command), &entry);
       lldb::offset_t entry_id_offset = load_cmd_offset + entry.entry_id.offset;
-      const char *id = data.GetCStr(&entry_id_offset);
-      entries.emplace_back(entry.vmaddr + slide, entry.fileoff,
-                           std::string(id));
+      if (const char *id = data.GetCStr(&entry_id_offset))
+        entries.emplace_back(entry.vmaddr + slide, entry.fileoff,
+                             std::string(id));
     }
 
     offset = load_cmd_offset + lc.cmdsize;

Copy link
Collaborator

@jasonmolenda jasonmolenda left a comment

Choose a reason for hiding this comment

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

LGTM. We'll skip any fileset entries that we can't read the filename of.

@JDevlieghere JDevlieghere merged commit 919caa8 into llvm:main Jul 10, 2024
6 of 7 checks passed
@JDevlieghere JDevlieghere deleted the rdar/131477833 branch July 10, 2024 21:17
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Jul 12, 2024
The memory read can fail for a malformed fileset. Handle it gracefully
instead of passing a nullptr to the std::string constructor.

rdar://131477833
(cherry picked from commit 919caa8)
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
The memory read can fail for a malformed fileset. Handle it gracefully
instead of passing a nullptr to the std::string constructor.

rdar://131477833
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants