Line | Count | Source |
1 | | /* Copyright 2022 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | |
13 | | #include <stddef.h> |
14 | | #include <stdint.h> |
15 | | #include <stdlib.h> |
16 | | #include <string> |
17 | | #include <sys/socket.h> |
18 | | |
19 | | #include <fuzzer/FuzzedDataProvider.h> |
20 | | |
21 | | #include "libevent/include/event2/event.h" |
22 | | #include "libevent/include/event2/util.h" |
23 | | #include "util-internal.h" |
24 | | |
25 | 1.34k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
26 | 1.34k | int r; |
27 | 1.34k | int len; |
28 | 1.34k | char out_buf[128]; |
29 | 1.34k | struct sockaddr_storage ss; |
30 | 1.34k | FuzzedDataProvider data_provider(data, size); |
31 | 1.34k | std::string fuzz_string = data_provider.ConsumeRandomLengthString(); |
32 | | |
33 | 1.34k | len = sizeof(out_buf); |
34 | 1.34k | r = evutil_parse_sockaddr_port( |
35 | 1.34k | fuzz_string.c_str(), (struct sockaddr*)&ss, &len); |
36 | 1.34k | if (r == 0) { |
37 | 255 | evutil_format_sockaddr_port_((struct sockaddr*)&ss, |
38 | 255 | out_buf, |
39 | 255 | sizeof(out_buf)); |
40 | 255 | } |
41 | | |
42 | 1.34k | struct evutil_addrinfo *addr_info = NULL; |
43 | 1.34k | std::string s1 = data_provider.ConsumeRandomLengthString(); |
44 | 1.34k | evutil_getaddrinfo(s1.c_str(), NULL, NULL, &addr_info); |
45 | 1.34k | if (addr_info != NULL) { |
46 | 107 | evutil_freeaddrinfo(addr_info); |
47 | 107 | } |
48 | | |
49 | 1.34k | int portnum=-1; |
50 | 1.34k | struct evutil_addrinfo *res = NULL; |
51 | 1.34k | struct evutil_addrinfo hints; |
52 | | |
53 | 1.34k | memset(&hints, 0, sizeof(hints)); |
54 | 1.34k | hints.ai_family = PF_UNSPEC; |
55 | 1.34k | evutil_getaddrinfo_common_(NULL, s1.c_str(), &hints, &res, &portnum); |
56 | 1.34k | if (res != NULL) { |
57 | 32 | evutil_freeaddrinfo(res); |
58 | 32 | } |
59 | | |
60 | 1.34k | res = NULL; |
61 | 1.34k | memset(&hints, 0, sizeof(hints)); |
62 | 1.34k | hints.ai_family = PF_UNSPEC; |
63 | 1.34k | evutil_getaddrinfo_common_(s1.c_str(), NULL, &hints, &res, &portnum); |
64 | 1.34k | if (res != NULL) { |
65 | 59 | evutil_freeaddrinfo(res); |
66 | 59 | } |
67 | | |
68 | 1.34k | return 0; |
69 | 1.34k | } |