[lld] 6b4f86f - Reapply: [MachO] Add a test for detecting reserved unit length.
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 21 02:01:25 PST 2020
Author: Igor Kudrin
Date: 2020-01-21T16:59:44+07:00
New Revision: 6b4f86f65f165249cbea1d23611ac97aeec7a082
URL: https://github.com/llvm/llvm-project/commit/6b4f86f65f165249cbea1d23611ac97aeec7a082
DIFF: https://github.com/llvm/llvm-project/commit/6b4f86f65f165249cbea1d23611ac97aeec7a082.diff
LOG: Reapply: [MachO] Add a test for detecting reserved unit length.
The test in the origin patch did not create a __debug_str section.
An UBSan check triggered when the corresponding pointer was dereferenced.
Differential Revision: https://reviews.llvm.org/D72695
This reapplies fcc08aa835de1e0c1f3e7e479917575e55433b68
which was reverted in b16f82ad3b095070729cde2873bd3a2e8ab35c0e.
Added:
Modified:
lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
Removed:
################################################################################
diff --git a/lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp b/lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
index cf9a845c4b26..19534eadaf5b 100644
--- a/lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
+++ b/lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
@@ -97,3 +97,44 @@ TEST(ToAtomsTest, basic_obj_x86_64) {
EXPECT_TRUE(atom4->name().equals("_undef"));
EXPECT_EQ(lld::Atom::definitionUndefined, atom4->definition());
}
+
+TEST(ToAtomsTest, reservedUnitLength) {
+ static const uint8_t debugInfoWithReservedLengthContent[12] = {
+ 0xf0, 0xff, 0xff, 0xff // Reserved length value
+ };
+ static const uint8_t debugInfoWithValidBigLengthContent[12] = {
+ 0xef, 0xff, 0xff, 0xff, // The maximum valid length value for DWARF32
+ 0x00, 0x00 // Wrong version
+ };
+ static const uint8_t dummyContent[] = {0x00};
+
+ NormalizedFile fReservedLength, fValidBigLength;
+ fReservedLength.arch = lld::MachOLinkingContext::arch_x86;
+ fValidBigLength.arch = lld::MachOLinkingContext::arch_x86;
+ Section section;
+ section.segmentName = "__DWARF";
+ section.sectionName = "__debug_info";
+ section.content = llvm::makeArrayRef(debugInfoWithReservedLengthContent);
+ fReservedLength.sections.push_back(section);
+ section.content = llvm::makeArrayRef(debugInfoWithValidBigLengthContent);
+ fValidBigLength.sections.push_back(section);
+ section.sectionName = "__debug_abbrev";
+ section.content = llvm::makeArrayRef(dummyContent);
+ fReservedLength.sections.push_back(section);
+ fValidBigLength.sections.push_back(section);
+ section.sectionName = "__debug_str";
+ fReservedLength.sections.push_back(section);
+ fValidBigLength.sections.push_back(section);
+
+ auto resultReservedLength = normalizedToAtoms(fReservedLength, "foo", false);
+ auto resultValidBigLength = normalizedToAtoms(fValidBigLength, "foo", false);
+
+ // Both cases should return errors, but
diff erent.
+ ASSERT_FALSE(resultReservedLength);
+ ASSERT_FALSE(resultValidBigLength);
+
+ EXPECT_STREQ("Malformed DWARF in foo",
+ toString(resultReservedLength.takeError()).c_str());
+ EXPECT_STREQ("Unsupported DWARF version in foo",
+ toString(resultValidBigLength.takeError()).c_str());
+}
More information about the llvm-commits
mailing list