Bug 1480654 - Allow empty eh_frame entries. r?froydnj draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 03 Aug 2018 11:33:49 +0900
changeset 826175 e80d4039fb2991f7f957eeff404212c7216df32c
parent 826174 dcea9f4775fa762440fc57968f7fb94c761d0d7c
child 826199 433ef961af6c988da746c1e96824b7cba8a9537e
push id118251
push userbmo:mh+mozilla@glandium.org
push dateFri, 03 Aug 2018 02:37:41 +0000
reviewersfroydnj
bugs1480654
milestone63.0a1
Bug 1480654 - Allow empty eh_frame entries. r?froydnj Somehow, when building with LTO, clang can end up creating a eh_frame section with only one, empty, entry (which just looks like a 4-bytes long section full of 0x00).
build/unix/elfhack/elfhack.cpp
--- a/build/unix/elfhack/elfhack.cpp
+++ b/build/unix/elfhack/elfhack.cpp
@@ -662,24 +662,30 @@ static void adjust_eh_frame(ElfSection* 
     char* data = const_cast<char*>(eh_frame->getData());
     size_t size = eh_frame->getSize();
     char LSDAencoding = DW_EH_PE_omit;
     char FDEencoding = DW_EH_PE_absptr;
     bool hasZ = false;
 
     // Decoding of eh_frame based on https://www.airs.com/blog/archives/460
     while (size) {
-        if (size < 2 * sizeof(uint32_t)) goto malformed;
+        if (size < sizeof(uint32_t)) goto malformed;
 
         serializable<FixedSizeData<uint32_t>> entryLength(data, size, elf->getClass(), elf->getData());
         if (!advance_buffer(&data, &size, sizeof(uint32_t))) goto malformed;
 
         char* cursor = data;
         size_t length = entryLength.value;
 
+        if (length == 0) {
+            continue;
+        }
+
+        if (size < sizeof(uint32_t)) goto malformed;
+
         serializable<FixedSizeData<uint32_t>> id(data, size, elf->getClass(), elf->getData());
         if (!advance_buffer(&cursor, &length, sizeof(uint32_t))) goto malformed;
 
         if (id.value == 0) {
             // This is a Common Information Entry
             if (length < 2) goto malformed;
             // Reset LSDA and FDE encodings, and hasZ for subsequent FDEs.
             LSDAencoding = DW_EH_PE_omit;