1 //
2 // Copyright 2022 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #include <stdint.h>
18 #include <string.h>
19
20 #include <string>
21
22 #include "absl/status/statusor.h"
23
24 #include <grpc/support/log.h>
25
26 #include "src/core/lib/address_utils/sockaddr_utils.h"
27 #include "src/core/lib/iomgr/resolve_address.h"
28 #include "src/core/lib/iomgr/resolved_address.h"
29 #include "src/core/lib/uri/uri_parser.h"
30
31 bool squelch = true;
32
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)33 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
34 if (size > GRPC_MAX_SOCKADDR_SIZE) return 0;
35 grpc_resolved_address address;
36 memset(&address, 0, sizeof(address));
37 memcpy(address.addr, data, size);
38 address.len = size;
39
40 absl::StatusOr<std::string> uri = grpc_sockaddr_to_uri(&address);
41 if (!uri.ok()) return 0;
42 absl::StatusOr<grpc_core::URI> parsed_uri =
43 grpc_core::URI::Parse(uri.value());
44
45 GPR_ASSERT(parsed_uri.ok());
46 return 0;
47 }
48