content_security_policy_fuzzer.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "services/network/public/cpp/content_security_policy/content_security_policy.h"
  5. #include <string>
  6. #include "base/at_exit.h"
  7. #include "base/command_line.h"
  8. #include "base/i18n/icu_util.h"
  9. #include "net/http/http_response_headers.h"
  10. #include "testing/libfuzzer/libfuzzer_exports.h"
  11. #include "url/gurl.h"
  12. namespace {
  13. struct Environment {
  14. Environment() {
  15. // This is a workaround for https://crbug.com/778929.
  16. CHECK(base::i18n::InitializeICU());
  17. base::CommandLine::Init(0, nullptr);
  18. }
  19. // used by ICU integration.
  20. base::AtExitManager at_exit_manager;
  21. };
  22. } // namespace
  23. namespace network {
  24. int LLVMFuzzerInitialize(int* argc, char*** argv) {
  25. static Environment env;
  26. return 0;
  27. }
  28. int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  29. ParseContentSecurityPolicies(
  30. std::string(reinterpret_cast<const char*>(data), size),
  31. network::mojom::ContentSecurityPolicyType::kEnforce,
  32. network::mojom::ContentSecurityPolicySource::kHTTP,
  33. GURL("https://example.com/"));
  34. return 0;
  35. }
  36. } // namespace network
  37. extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
  38. return network::LLVMFuzzerInitialize(argc, argv);
  39. }
  40. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  41. return network::LLVMFuzzerTestOneInput(data, size);
  42. }