• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <stddef.h>
6 #include <stdint.h>
7 #include <string>
8 
9 #include <fuzzer/FuzzedDataProvider.h>
10 
11 #include "base/test/scoped_feature_list.h"
12 #include "net/base/features.h"
13 #include "net/cookies/cookie_partition_key.h"
14 #include "url/origin.h"
15 
16 namespace net {
17 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)18 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
19   base::test::ScopedFeatureList scoped_feature_list;
20   scoped_feature_list.InitAndEnableFeature(features::kPartitionedCookies);
21 
22   FuzzedDataProvider data_provider(data, size);
23 
24   std::string url_str = data_provider.ConsumeRandomLengthString(800);
25   GURL url(url_str);
26   if (!url.is_valid())
27     return 0;
28 
29   absl::optional<CookiePartitionKey> partition_key =
30       absl::make_optional(CookiePartitionKey::FromURLForTesting(url));
31 
32   bool is_opaque = url::Origin::Create(url).opaque();
33   std::string tmp;
34   CHECK_NE(is_opaque, CookiePartitionKey::Serialize(partition_key, tmp));
35 
36   CHECK_NE(is_opaque, CookiePartitionKey::Deserialize(url_str, partition_key));
37 
38   if (!is_opaque) {
39     CHECK(absl::make_optional(CookiePartitionKey::FromURLForTesting(url)) ==
40           partition_key);
41   }
42 
43   return 0;
44 }
45 
46 }  // namespace net
47