Bug 1480654 - Allow empty eh_frame entries. r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 03 Aug 2018 11:33:49 +0900
changeset 826526 d2eea4c02840f08c9cb383942614a19eab4d38e3
parent 826525 c0b095a6a2c93620a65721f6eb63005760ede156
child 826527 a2269f12b9d7fcc1d17bb3721464d02ef82c7b77
push id118355
push userwisniewskit@gmail.com
push dateSat, 04 Aug 2018 00:24:59 +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;