[PATCH] D42827: Don't accept unsuitable ELF files such as executables or core files.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 16:04:56 PST 2018


ruiu created this revision.
ruiu added a reviewer: rafael.
Herald added a subscriber: emaste.

Don't accept unsuitable ELF files such as executables or core files.


https://reviews.llvm.org/D42827

Files:
  lld/ELF/Driver.cpp
  lld/test/ELF/invalid/Inputs/too-short.elf
  lld/test/ELF/invalid/executable.s
  lld/test/ELF/invalid/too-short.s


Index: lld/test/ELF/invalid/too-short.s
===================================================================
--- lld/test/ELF/invalid/too-short.s
+++ /dev/null
@@ -1,5 +0,0 @@
-# REQUIRES: x86
-
-## too-short.elf file is a truncated ELF.
-# RUN: not ld.lld %S/Inputs/too-short.elf -o %t 2>&1 | FileCheck %s
-# CHECK: file is too short
Index: lld/test/ELF/invalid/executable.s
===================================================================
--- /dev/null
+++ lld/test/ELF/invalid/executable.s
@@ -0,0 +1,9 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld -o %t1.exe %t.o
+# RUN: not ld.lld -o %t2.exe %t1.exe 2>&1 | FileCheck %s
+# CHECK: unknown file type
+
+.global _start
+_start:
+  ret
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -228,11 +228,15 @@
     Files.push_back(
         createSharedFile(MBRef, WithLOption ? path::filename(Path) : Path));
     return;
-  default:
+  case file_magic::elf_relocatable:
+  case file_magic::bitcode:
     if (InLib)
       Files.push_back(make<LazyObjFile>(MBRef, "", 0));
     else
       Files.push_back(createObjectFile(MBRef));
+    break;
+  default:
+    error(Path + ": unknown file type");
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42827.132499.patch
Type: text/x-patch
Size: 1310 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180202/21494280/attachment.bin>


More information about the llvm-commits mailing list