Index: base/test/fuzzed_data_provider.cc |
diff --git a/base/test/fuzzed_data_provider.cc b/base/test/fuzzed_data_provider.cc |
index 3045e693a75f9eee407538809731a00eee9d160f..14ffb12a648f08008d52a5d730f43bbd6ab4d9db 100644 |
--- a/base/test/fuzzed_data_provider.cc |
+++ b/base/test/fuzzed_data_provider.cc |
@@ -54,6 +54,28 @@ uint32_t FuzzedDataProvider::ConsumeUint32InRange(uint32_t min, uint32_t max) { |
return min + result % (range + 1); |
} |
+std::string FuzzedDataProvider::ConsumeRandomLengthString(size_t max_length) { |
+ // Reads bytes from start of |remaining_data_|. Maps "\\" to "\", and maps "\" |
Paweł Hajdan Jr.
2016/11/15 13:38:50
Why do we care about backslashes?
Is this the rig
mmenke
2016/11/15 13:43:48
I'm not following. We need a random string that c
mmenke
2016/11/15 13:46:59
Sorry, "From length 0 to max_length".
mmenke
2016/11/15 13:55:32
And, just so we're on the same page, the fuzzers g
|
+ // followed by anything else to the end of the string. As a result of this |
+ // logic, a fuzzer can insert characters into the string, and the string will |
+ // be lengthened to include those new characters, resulting in a more stable |
+ // fuzzer than picking the length of a string independently from picking its |
+ // contents. |
+ std::string out; |
+ for (size_t i = 0; i < max_length && !remaining_data_.empty(); ++i) { |
+ char next = remaining_data_[0]; |
+ remaining_data_.remove_prefix(1); |
+ if (next == '\\' && !remaining_data_.empty()) { |
+ next = remaining_data_[0]; |
+ remaining_data_.remove_prefix(1); |
+ if (next != '\\') |
+ return out; |
+ } |
+ out += next; |
+ } |
+ return out; |
+} |
+ |
int FuzzedDataProvider::ConsumeInt32InRange(int min, int max) { |
CHECK_LE(min, max); |