0

Add a fuzzer for the feature policy string parser.

Review-Url: https://codereview.chromium.org/2420013004
Cr-Commit-Position: refs/heads/master@{#429705}
This commit is contained in:
iclelland
2016-11-03 14:57:29 -07:00
committed by Commit bot
parent 9334c34dbc
commit f9e719920a
17 changed files with 76 additions and 0 deletions
testing/libfuzzer/fuzzers
dicts
feature_policy_corpus
third_party/WebKit/Source/platform

@ -0,0 +1,20 @@
# Copyright 2016 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.
"\"cookie\""
"\"domain\""
"\"docwrite\""
"\"geolocation\""
"\"midi\""
"\"notifications\""
"\"payment\""
"\"push\""
"\"sync-script\""
"\"sync-xhr\""
"\"usermedia\""
"\"vibrate\""
"\"webrtc\""
"\"https://example.com/\""
"*"
"\"self\""

@ -0,0 +1 @@
Not a JSON literal

@ -0,0 +1 @@
{"vibrate": ["self", "https://example.com/"]},{"vibrate": ["self", "https://example.net/"]}

@ -0,0 +1 @@
{"vibrate": ["self", "https://example.org/"]}

@ -0,0 +1 @@
{"docwrite": ["self", "https://example.org/"]}

@ -0,0 +1 @@
{"vibrate": ["self", "https://example.net/"]}, {"docwrite": ["self"]}

@ -0,0 +1 @@
{"vibrate": ["*"]}, {"docwrite": ["*"]}

@ -0,0 +1 @@
"Not a JSON array"

@ -0,0 +1 @@
{"Also": "Not a JSON array"}

@ -0,0 +1 @@
1.0

@ -0,0 +1 @@
[{"vibrate": ["self"]}]

@ -0,0 +1 @@
{"vibrate": ["https://example.com/"]}

@ -0,0 +1 @@
{"docwrite": []}

@ -0,0 +1 @@
{"docwrite": ["self"]}

@ -0,0 +1 @@
{"vibrate": ["*"]}

@ -1952,6 +1952,19 @@ fuzzer_test("blink_json_parser_fuzzer") {
dict = "//testing/libfuzzer/fuzzers/dicts/json.dict"
}
# Fuzzer for blink::FeaturePolicy.
fuzzer_test("feature_policy_fuzzer") {
sources = [
"feature_policy/FeaturePolicyFuzzer.cpp",
]
deps = [
":blink_fuzzer_test_support",
":platform",
]
dict = "//testing/libfuzzer/fuzzers/dicts/feature_policy.dict"
seed_corpus = "//testing/libfuzzer/fuzzers/feature_policy_corpus"
}
# NOTE: These are legacy unit tests and tests that require a Platform
# object. Do not add more unless the test requires a Platform object.
# These tests are a part of the webkit_unit_tests binary.

@ -0,0 +1,29 @@
// Copyright 2016 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 "platform/feature_policy/FeaturePolicy.h"
#include "platform/heap/Handle.h"
#include "platform/testing/BlinkFuzzerTestSupport.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "wtf/Vector.h"
#include "wtf/text/WTFString.h"
#include <memory>
#include <stddef.h>
#include <stdint.h>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
WTF::Vector<WTF::String> messages;
RefPtr<blink::SecurityOrigin> origin =
blink::SecurityOrigin::createFromString("https://example.com/");
std::unique_ptr<blink::FeaturePolicy> policy =
blink::FeaturePolicy::createFromParentPolicy(nullptr, origin);
policy->setHeaderPolicy(WTF::String(data, size), messages);
return 0;
}
extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
blink::InitializeBlinkFuzzTest(argc, argv);
return 0;
}