[compiler-rt] 2136d17 - [compiler-rt] Add ConsumeRandomLengthString() version without arguments.
Max Moroz via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 23 16:33:18 PDT 2020
Author: Max Moroz
Date: 2020-03-23T16:32:37-07:00
New Revision: 2136d17d8dec4b5bd47d2ba2b48866c34c55e56d
URL: https://github.com/llvm/llvm-project/commit/2136d17d8dec4b5bd47d2ba2b48866c34c55e56d
DIFF: https://github.com/llvm/llvm-project/commit/2136d17d8dec4b5bd47d2ba2b48866c34c55e56d.diff
LOG: [compiler-rt] Add ConsumeRandomLengthString() version without arguments.
Reviewers: hctim, metzman
Subscribers: dberris, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D76448
Added:
Modified:
compiler-rt/include/fuzzer/FuzzedDataProvider.h
compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp
Removed:
################################################################################
diff --git a/compiler-rt/include/fuzzer/FuzzedDataProvider.h b/compiler-rt/include/fuzzer/FuzzedDataProvider.h
index bdeff21b1294..9be9c884f0ea 100644
--- a/compiler-rt/include/fuzzer/FuzzedDataProvider.h
+++ b/compiler-rt/include/fuzzer/FuzzedDataProvider.h
@@ -139,6 +139,11 @@ class FuzzedDataProvider {
return result;
}
+ // Returns a std::string of length from 0 to |remaining_bytes_|.
+ std::string ConsumeRandomLengthString() {
+ return ConsumeRandomLengthString(remaining_bytes_);
+ }
+
// Returns a std::vector containing all remaining bytes of the input data.
template <typename T> std::vector<T> ConsumeRemainingBytes() {
return ConsumeBytes<T>(remaining_bytes_);
diff --git a/compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp b/compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp
index 5eb46533d98a..99d9d8ecbe9b 100644
--- a/compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp
+++ b/compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp
@@ -190,14 +190,26 @@ TEST(FuzzedDataProvider, ConsumeRandomLengthString) {
"\x1D\xBD\x4E\x17\x04\x1E\xBA\x26\xAC\x1F\xE3\x37\x1C\x15\x43"
"\x60\x41\x2A\x7C\xCA\x70\xCE\xAB\x20\x24\xF8\xD9\x1F\x14\x7C"),
DataProv.ConsumeRandomLengthString(31337));
- EXPECT_EQ(std::string(Data + 141, Data + 141 + 5),
+ size_t Offset = 141;
+ EXPECT_EQ(std::string(Data + Offset, Data + Offset + 5),
DataProv.ConsumeRandomLengthString(5));
- EXPECT_EQ(std::string(Data + 141 + 5, Data + 141 + 5 + 2),
+ Offset += 5;
+ EXPECT_EQ(std::string(Data + Offset, Data + Offset + 2),
DataProv.ConsumeRandomLengthString(2));
+ Offset += 2;
+
+ // Call the overloaded method without arguments (uses max length available).
+ EXPECT_EQ(std::string(Data + Offset, Data + Offset + 664),
+ DataProv.ConsumeRandomLengthString());
+ Offset += 664 + 2; // +2 because of '\' character followed by any other byte.
+
+ EXPECT_EQ(std::string(Data + Offset, Data + Offset + 92),
+ DataProv.ConsumeRandomLengthString());
+ Offset += 92 + 2;
// Exhaust the buffer.
auto String = DataProv.ConsumeBytesAsString(31337);
- EXPECT_EQ(size_t(876), String.length());
+ EXPECT_EQ(size_t(116), String.length());
EXPECT_EQ(std::string(), DataProv.ConsumeRandomLengthString(1));
}
More information about the llvm-commits
mailing list