diff options
| author | Kostya Serebryany <kcc@google.com> | 2013-01-25 12:22:21 +0000 |
|---|---|---|
| committer | Kostya Serebryany <kcc@google.com> | 2013-01-25 12:22:21 +0000 |
| commit | c1056f90ae31eab1e42b83108520b96c62e8b726 (patch) | |
| tree | 5fd280cb95684598e47bf5b7e16b9a484a136e45 /compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc | |
| parent | fa79cd65e2a08979c0d76b6f0dec6192161e5611 (diff) | |
| download | bcm5719-llvm-c1056f90ae31eab1e42b83108520b96c62e8b726.tar.gz bcm5719-llvm-c1056f90ae31eab1e42b83108520b96c62e8b726.zip | |
[sanitizer] improve the calloc overflow check (spotted by samsonov@)
llvm-svn: 173443
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc')
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc index 26baf73a1f3..88a3a1b2569 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc @@ -76,8 +76,9 @@ void SetLowLevelAllocateCallback(LowLevelAllocateCallback callback) { } bool CallocShouldReturnNullDueToOverflow(uptr size, uptr n) { - uptr mul = size * n; - return mul < size || mul < n; + if (!size) return false; + uptr max = (uptr)-1L; + return (max / size) < n; } } // namespace __sanitizer |

