Commit 49b0cf54 authored by Dan McArdle's avatar Dan McArdle Committed by Chromium LUCI CQ

Add robots_rules_parser_fuzzer

Change-Id: I8bf824819ea496cd3fa50d9b6b82c6085948c3e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2625993Reviewed-by: default avatarrajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarOliver Chang <ochang@chromium.org>
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846154}
parent 7b5df013
......@@ -12,6 +12,7 @@ import("//components/spellcheck/spellcheck_build_features.gni")
import("//extensions/buildflags/buildflags.gni")
import("//media/media_options.gni")
import("//ppapi/buildflags/buildflags.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
import("//third_party/widevine/cdm/widevine.gni")
import("//tools/grit/grit_rule.gni")
......@@ -421,3 +422,21 @@ static_library("renderer") {
deps += [ "//chrome/common/performance_manager/mojom" ]
}
}
fuzzer_test("robots_rules_parser_fuzzer") {
sources = [
"subresource_redirect/robots_rules_parser.cc",
"subresource_redirect/robots_rules_parser.h",
"subresource_redirect/robots_rules_parser_fuzzer.cc",
"subresource_redirect/subresource_redirect_params.cc",
"subresource_redirect/subresource_redirect_params.h",
]
deps = [
"//base",
"//base/test:test_support",
"//chrome/common:constants",
"//components/subresource_redirect/proto",
"//third_party/blink/public/common",
"//third_party/icu/fuzzers:fuzzer_support",
]
}
......@@ -4,6 +4,7 @@ include_rules = [
"+components/subresource_redirect",
"+components/subresource_redirect/proto/robots_rules.pb.h",
"+services/network/test/test_utils.h",
"+third_party/icu/fuzzers/fuzzer_utils.h",
]
# These are browser tests that access both code from the browser and the
......
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fuzzer/FuzzedDataProvider.h>
#include <stddef.h>
#include <stdint.h>
#include "base/command_line.h"
#include "base/optional.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.h"
#include "third_party/icu/fuzzers/fuzzer_utils.h"
#include "chrome/renderer/subresource_redirect/robots_rules_parser.h"
namespace subresource_redirect {
namespace {
class Environment {
public:
Environment() {
base::CommandLine::Init(0, nullptr);
TestTimeouts::Initialize();
task_env_.emplace(); // Construct after calling TestTimeouts::Initialize().
}
private:
IcuEnvironment icu;
base::Optional<base::test::SingleThreadTaskEnvironment> task_env_;
};
} // namespace
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
static Environment env;
FuzzedDataProvider provider(data, size);
std::string rules = provider.ConsumeRandomLengthString();
std::string url = provider.ConsumeRandomLengthString();
base::RunLoop run_loop;
RobotsRulesParser parser;
parser.UpdateRobotsRules({std::move(rules)});
parser.CheckRobotsRules(0, GURL(std::move(url)),
base::BindOnce(
[](base::RepeatingClosure run_loop_quit,
RobotsRulesParser::CheckResult result) {
std::move(run_loop_quit).Run();
},
run_loop.QuitClosure()));
run_loop.RunUntilIdle();
return 0;
}
} // namespace subresource_redirect
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment