Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1867)

Unified Diff: base/test/fuzzed_data_provider.cc

Issue 2469813002: Add a URLRequest FTP fuzzer. (Closed)
Patch Set: Fix merge of net/BUILD.gn Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/test/fuzzed_data_provider.h ('k') | net/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « base/test/fuzzed_data_provider.h ('k') | net/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698