summaryrefslogtreecommitdiff
path: root/lib/ubsan/ubsan_handlers.cc
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2017-06-12 18:42:51 +0000
committerVedant Kumar <vsk@apple.com>2017-06-12 18:42:51 +0000
commit079b7657767dcc0fb284225c277d2b9ce73e423b (patch)
tree397be1511cdd1accb55cbc1eb8a563bdd306b6cb /lib/ubsan/ubsan_handlers.cc
parenta2b9a14ce8ed68ce8678fb20a25a140a011a9198 (diff)
[ubsan] Detect invalid unsigned pointer index expression (compiler-rt)
Compiler-rt part of: https://reviews.llvm.org/D33910 Differential Revision: https://reviews.llvm.org/D33911 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@305217 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ubsan/ubsan_handlers.cc')
-rw-r--r--lib/ubsan/ubsan_handlers.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/ubsan/ubsan_handlers.cc b/lib/ubsan/ubsan_handlers.cc
index 80cc8ad25..5dabbd8e0 100644
--- a/lib/ubsan/ubsan_handlers.cc
+++ b/lib/ubsan/ubsan_handlers.cc
@@ -566,8 +566,14 @@ static void handlePointerOverflowImpl(PointerOverflowData *Data,
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,