[llvm] r347281 - [ExecutionEngine][Interpreter] Fix out-of-bounds array access.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 19 17:01:26 PST 2018


Author: lhames
Date: Mon Nov 19 17:01:26 2018
New Revision: 347281

URL: http://llvm.org/viewvc/llvm-project?rev=347281&view=rev
Log:
[ExecutionEngine][Interpreter] Fix out-of-bounds array access.

If args is empty then accesing element 0 is illegal.

https://reviews.llvm.org/D53556

Patch by Eugene Sharygin. Thanks Eugene!

Added:
    llvm/trunk/test/ExecutionEngine/Interpreter/call-no-args.ll
Modified:
    llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp

Modified: llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp?rev=347281&r1=347280&r2=347281&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp Mon Nov 19 17:01:26 2018
@@ -227,7 +227,8 @@ static bool ffiInvoke(RawFunc Fn, Functi
   Type *RetTy = FTy->getReturnType();
   ffi_type *rtype = ffiTypeFor(RetTy);
 
-  if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, NumArgs, rtype, &args[0]) == FFI_OK) {
+  if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, NumArgs, rtype, args.data()) ==
+      FFI_OK) {
     SmallVector<uint8_t, 128> ret;
     if (RetTy->getTypeID() != Type::VoidTyID)
       ret.resize(TD.getTypeStoreSize(RetTy));

Added: llvm/trunk/test/ExecutionEngine/Interpreter/call-no-args.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/Interpreter/call-no-args.ll?rev=347281&view=auto
==============================================================================
--- llvm/trunk/test/ExecutionEngine/Interpreter/call-no-args.ll (added)
+++ llvm/trunk/test/ExecutionEngine/Interpreter/call-no-args.ll Mon Nov 19 17:01:26 2018
@@ -0,0 +1,10 @@
+; RUN: %lli -force-interpreter %s
+
+declare void @exit(i32)
+declare i32 @rand()
+
+define i32 @main() {
+  %ret = call i32 @rand()
+  call void @exit(i32 0)
+  ret i32 %ret
+}




More information about the llvm-commits mailing list