Skip to content

Commit a44ef02

Browse files
committed
[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.
1 parent b89ba5f commit a44ef02

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

compiler-rt/include/fuzzer/FuzzedDataProvider.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ class FuzzedDataProvider {
263263
// which seems to be a natural choice for other implementations as well.
264264
// To increase the odds even more, we also call |shrink_to_fit| below.
265265
std::vector<T> result(size);
266+
if (size == 0) {
267+
if (num_bytes_to_consume != 0)
268+
abort();
269+
return result;
270+
}
271+
266272
std::memcpy(result.data(), data_ptr_, num_bytes_to_consume);
267273
Advance(num_bytes_to_consume);
268274

0 commit comments

Comments
 (0)