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 "net/cookies/cookie_partition_key.h" 12 #include "url/origin.h" 13 14 namespace net { 15 LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)16extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 17 FuzzedDataProvider data_provider(data, size); 18 19 std::string url_str = data_provider.ConsumeRandomLengthString(800); 20 GURL url(url_str); 21 if (!url.is_valid()) 22 return 0; 23 24 std::optional<CookiePartitionKey> partition_key = 25 std::make_optional(CookiePartitionKey::FromURLForTesting(url)); 26 27 bool is_opaque = url::Origin::Create(url).opaque(); 28 CHECK_NE(is_opaque, CookiePartitionKey::Serialize(partition_key).has_value()); 29 30 CHECK_NE(is_opaque, CookiePartitionKey::FromUntrustedInput( 31 url_str, partition_key->IsThirdParty()) 32 .has_value()); 33 34 if (!is_opaque) { 35 CHECK(std::make_optional(CookiePartitionKey::FromURLForTesting(url)) == 36 partition_key); 37 } 38 39 return 0; 40 } 41 42 } // namespace net 43