[compiler-rt] a44ef02 - [compiler-rt] FuzzedDataProvider: do not call memcpy on empty vector.
Max Moroz via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 4 14:21:07 PST 2019
Author: Max Moroz
Date: 2019-12-04T14:18:52-08:00
New Revision: a44ef027ebca1598892ea9b104d6189aeb3bc2f0
URL: https://github.com/llvm/llvm-project/commit/a44ef027ebca1598892ea9b104d6189aeb3bc2f0
DIFF: https://github.com/llvm/llvm-project/commit/a44ef027ebca1598892ea9b104d6189aeb3bc2f0.diff
LOG: [compiler-rt] FuzzedDataProvider: do not call memcpy on empty vector.
Summary:
Some versions of memcpy mark pointer arguments as __nonnull, that triggers UBSan
errors even when the length passed is 0.
Reviewers: manojgupta, metzman
Subscribers: dberris, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D71031
[compiler-rt] FDP: assert that num_bytes_to_consume == 0 when size == 0.
Added:
Modified:
compiler-rt/include/fuzzer/FuzzedDataProvider.h
Removed:
################################################################################
diff --git a/compiler-rt/include/fuzzer/FuzzedDataProvider.h b/compiler-rt/include/fuzzer/FuzzedDataProvider.h
index fd895b767d9e..3e069eba69b4 100644
--- a/compiler-rt/include/fuzzer/FuzzedDataProvider.h
+++ b/compiler-rt/include/fuzzer/FuzzedDataProvider.h
@@ -263,6 +263,12 @@ class FuzzedDataProvider {
// which seems to be a natural choice for other implementations as well.
// To increase the odds even more, we also call |shrink_to_fit| below.
std::vector<T> result(size);
+ if (size == 0) {
+ if (num_bytes_to_consume != 0)
+ abort();
+ return result;
+ }
+
std::memcpy(result.data(), data_ptr_, num_bytes_to_consume);
Advance(num_bytes_to_consume);
More information about the llvm-commits
mailing list