[PATCH] D71031: [compiler-rt] FuzzedDataProvider: do not call memcpy on empty vector.

Max Moroz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 4 13:32:26 PST 2019


Dor1s created this revision.
Dor1s added reviewers: manojgupta, metzman.
Herald added subscribers: llvm-commits, Sanitizers, dberris.
Herald added projects: Sanitizers, LLVM.
Dor1s updated this revision to Diff 232196.
Dor1s added a comment.
Dor1s accepted this revision.
This revision is now accepted and ready to land.

- remove empty line


Dor1s added a comment.

TBR simple change.


Some versions of memcpy mark pointer arguments as __nonnull, that triggers UBSan
errors even when the length passed is 0.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71031

Files:
  compiler-rt/include/fuzzer/FuzzedDataProvider.h


Index: compiler-rt/include/fuzzer/FuzzedDataProvider.h
===================================================================
--- compiler-rt/include/fuzzer/FuzzedDataProvider.h
+++ compiler-rt/include/fuzzer/FuzzedDataProvider.h
@@ -263,6 +263,9 @@
     // 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)
+      return result;
+
     std::memcpy(result.data(), data_ptr_, num_bytes_to_consume);
     Advance(num_bytes_to_consume);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71031.232196.patch
Type: text/x-patch
Size: 583 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191204/140d43f0/attachment.bin>


More information about the llvm-commits mailing list