<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - llvm-readobj reads past end of dynamic segment if it does not end in DT_NULL"
   href="https://bugs.llvm.org/show_bug.cgi?id=40861">40861</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm-readobj reads past end of dynamic segment if it does not end in DT_NULL
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>llvm-readobj
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jh7370.2008@my.bristol.ac.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>jh7370.2008@my.bristol.ac.uk, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Generating a dynamic segment with the following yaml results in there being no
DT_NULL entry at the end of the segment:
--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:         .dynamic
    Type:         SHT_DYNAMIC
    AddressAlign: 0x10
    Address:      0x1010
    # DT_DEBUG tag only, no DT_NULL tag.
    Content: "15000000000000000000000000000000"
ProgramHeaders:
  - Type: PT_LOAD
    VAddr: 0x1000
    Sections:
      - Section: .dynstr
      - Section: .dynamic
  - Type: PT_DYNAMIC
    VAddr: 0x1010
    Sections:
      - Section: .dynamic

Although strictly speaking this is illegal, GNU readelf handles it sensibly,
because the size is listed in the program header:
C:\Work> readelf --dynamic test.tmp.no-null

Dynamic section at offset 0x1f0 contains 1 entries:
  Tag        Type                         Name/Value
 0x0000000000000015 (DEBUG)              0x0

However, llvm-readobj does not. It assumes that there is always a trailing
DT_NULL entry, and reads past the end of the segment if there is none to find
it:
C:\Work> llvm-readobj.exe --dynamic-table test.tmp.no-null
<snip>
DynamicSection [ (2 entries)
  Tag                Type                 Name/Value
  0x0000000000000015 DEBUG                0x0
  0x0000000000000000 NULL                 0x0
]

I'm guessing, but don't know for sure, that the non-existent NULL entry is
printed as such because the next 16 bytes happen to be all 0 in the file.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>