[PATCH] D33911: [ubsan] Detect invalid unsigned pointer index expression (compiler-rt)
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 12 11:43:36 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305217: [ubsan] Detect invalid unsigned pointer index expression (compiler-rt) (authored by vedantk).
Changed prior to commit:
https://reviews.llvm.org/D33911?vs=101496&id=102215#toc
Repository:
rL LLVM
https://reviews.llvm.org/D33911
Files:
compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
compiler-rt/trunk/test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp
Index: compiler-rt/trunk/test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp
===================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp
+++ compiler-rt/trunk/test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp
@@ -0,0 +1,13 @@
+// RUN: %clangxx -fsanitize=pointer-overflow %s -o %t
+// RUN: %t 2>&1 | FileCheck %s
+
+int main(int argc, char *argv[]) {
+ char c;
+ char *p = &c;
+ unsigned long long offset = -1;
+
+ // CHECK: unsigned-index-expression.cpp:[[@LINE+1]]:15: runtime error: unsigned pointer index expression result is 0x{{.*}}, preceding its base 0x{{.*}}
+ char *q = p + offset;
+
+ return 0;
+}
Index: compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
===================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
@@ -566,8 +566,14 @@
ScopedReport R(Opts, Loc, ET);
- Diag(Loc, DL_Error, "pointer index expression with base %0 overflowed to %1")
- << (void *)Base << (void*)Result;
+ if ((sptr(Base) >= 0) == (sptr(Result) >= 0))
+ Diag(Loc, DL_Error, "unsigned pointer index expression result is %0, "
+ "preceding its base %1")
+ << (void *)Result << (void *)Base;
+ else
+ Diag(Loc, DL_Error,
+ "pointer index expression with base %0 overflowed to %1")
+ << (void *)Base << (void *)Result;
}
void __ubsan::__ubsan_handle_pointer_overflow(PointerOverflowData *Data,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33911.102215.patch
Type: text/x-patch
Size: 1563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170612/2440b906/attachment.bin>
More information about the llvm-commits
mailing list