• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/log/check.h"
23 #include "absl/status/statusor.h"
24 #include "src/core/lib/address_utils/sockaddr_utils.h"
25 #include "src/core/lib/iomgr/resolve_address.h"
26 #include "src/core/lib/iomgr/resolved_address.h"
27 #include "src/core/util/uri.h"
28 
29 bool squelch = true;
30 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)31 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
32   if (size > GRPC_MAX_SOCKADDR_SIZE) return 0;
33   grpc_resolved_address address;
34   memset(&address, 0, sizeof(address));
35   memcpy(address.addr, data, size);
36   address.len = size;
37 
38   absl::StatusOr<std::string> uri = grpc_sockaddr_to_uri(&address);
39   if (!uri.ok()) return 0;
40   absl::StatusOr<grpc_core::URI> parsed_uri =
41       grpc_core::URI::Parse(uri.value());
42 
43   CHECK_OK(parsed_uri);
44   return 0;
45 }
46