[JITLink][ELF] Check that ELF buffer has at least ELF::EI_NIDENT bytes.
authorLang Hames <lhames@gmail.com>
Mon, 17 Apr 2023 17:58:29 +0000 (10:58 -0700)
committerLang Hames <lhames@gmail.com>
Mon, 17 Apr 2023 18:42:27 +0000 (11:42 -0700)
This allows the subsequent code to access the E_IDENT fields, which will be
used in the upcoming JITLink ppc64 backend (https://reviews.llvm.org/D148192).

llvm/lib/ExecutionEngine/JITLink/ELF.cpp

index 340a0ce..e35f8a3 100644 (file)
@@ -57,7 +57,7 @@ Expected<uint16_t> readTargetMachineArch(StringRef Buffer) {
 Expected<std::unique_ptr<LinkGraph>>
 createLinkGraphFromELFObject(MemoryBufferRef ObjectBuffer) {
   StringRef Buffer = ObjectBuffer.getBuffer();
-  if (Buffer.size() < ELF::EI_MAG3 + 1)
+  if (Buffer.size() < ELF::EI_NIDENT)
     return make_error<JITLinkError>("Truncated ELF buffer");
 
   if (memcmp(Buffer.data(), ELF::ElfMagic, strlen(ELF::ElfMagic)) != 0)