[PATCH] D53556: [ExecutionEngine] Fix out-of-bounds access in the interpreter

Eugene Sharygin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 22 23:32:19 PDT 2018


eush created this revision.

This commit fixes "attempt to subscript container with out-of-bounds
index" error reported by the GNU C++ Library in debug mode (enabled by
LLVM_ENABLE_EXPENSIVE_CHECKS).


Repository:
  rL LLVM

https://reviews.llvm.org/D53556

Files:
  lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
  test/ExecutionEngine/Interpreter/rand.ll


Index: test/ExecutionEngine/Interpreter/rand.ll
===================================================================
--- /dev/null
+++ test/ExecutionEngine/Interpreter/rand.ll
@@ -0,0 +1,10 @@
+; RUN: lli -O0 -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
+}
Index: lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
===================================================================
--- lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -227,7 +227,8 @@
   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));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53556.170572.patch
Type: text/x-patch
Size: 1026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181023/8aeeb944/attachment.bin>


More information about the llvm-commits mailing list