[PATCH] D87074: [StackProtector] Fix crash with vararg due to not checking LocationSize validity.

Amara Emerson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 2 23:21:30 PDT 2020


aemerson created this revision.
aemerson added reviewers: john.brawn, eli.friedman.
aemerson added a project: LLVM.
Herald added a subscriber: hiraditya.
aemerson requested review of this revision.

This seems to have been introduced in D75695 <https://reviews.llvm.org/D75695>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87074

Files:
  llvm/lib/CodeGen/StackProtector.cpp
  llvm/test/CodeGen/X86/stack-guard-memloc-vararg.ll


Index: llvm/test/CodeGen/X86/stack-guard-memloc-vararg.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/stack-guard-memloc-vararg.ll
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple=x86_64 -O0 < %s | FileCheck %s
+
+; Check that we don't crash on this input.
+; CHECK-LABEL: @foo
+; CHECK: __stack_chk_guard
+; CHECK: retq
+define hidden void @foo(i8** %ptr) #0 {
+entry:
+  %args.addr = alloca i8*, align 8
+  %0 = va_arg i8** %args.addr, i8*
+  store i8* %0, i8** %ptr
+  ret void
+}
+
+attributes #0 = { sspstrong }
+attributes #1 = { optsize }
+
Index: llvm/lib/CodeGen/StackProtector.cpp
===================================================================
--- llvm/lib/CodeGen/StackProtector.cpp
+++ llvm/lib/CodeGen/StackProtector.cpp
@@ -170,7 +170,8 @@
     // If this instruction accesses memory make sure it doesn't access beyond
     // the bounds of the allocated object.
     Optional<MemoryLocation> MemLoc = MemoryLocation::getOrNone(I);
-    if (MemLoc.hasValue() && MemLoc->Size.getValue() > AllocSize)
+    if (MemLoc.hasValue() && MemLoc->Size.hasValue() &&
+        MemLoc->Size.getValue() > AllocSize)
       return true;
     switch (I->getOpcode()) {
     case Instruction::Store:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87074.289645.patch
Type: text/x-patch
Size: 1255 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200903/b4d81495/attachment.bin>


More information about the llvm-commits mailing list