schemeful_site_fuzzer.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2021 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 "net/base/schemeful_site.h"
  5. #include <stdlib.h>
  6. #include <iostream>
  7. #include <string>
  8. #include "testing/libfuzzer/proto/lpm_interface.h"
  9. #include "testing/libfuzzer/proto/url.pb.h"
  10. #include "testing/libfuzzer/proto/url_proto_converter.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. #include "url/gurl.h"
  13. #include "url/origin.h"
  14. DEFINE_PROTO_FUZZER(const url_proto::Url& url_message) {
  15. std::string native_input = url_proto::Convert(url_message);
  16. if (getenv("LPM_DUMP_NATIVE_INPUT"))
  17. std::cout << native_input << std::endl;
  18. url::Origin origin = url::Origin::Create((GURL(native_input)));
  19. // We don't run the fuzzer on inputs whose hosts will contain "..". The ".."
  20. // causes SchemefulSite to consider the registrable domain to start with the
  21. // second ".".
  22. if (origin.host().find("..") != std::string::npos)
  23. return;
  24. net::SchemefulSite site(origin);
  25. absl::optional<net::SchemefulSite> site_with_registrable_domain =
  26. net::SchemefulSite::CreateIfHasRegisterableDomain(origin);
  27. if (site_with_registrable_domain) {
  28. CHECK_EQ(site_with_registrable_domain->GetInternalOriginForTesting(),
  29. site.GetInternalOriginForTesting());
  30. CHECK(site.has_registrable_domain_or_host());
  31. const std::string& scheme = site.GetInternalOriginForTesting().scheme();
  32. if (scheme == "http" || scheme == "https") {
  33. CHECK_NE(site.registrable_domain_or_host_for_testing().front(), '.');
  34. }
  35. }
  36. }