/src/gnutls/fuzz/gnutls_client_fuzzer.c
Line | Count | Source |
1 | | /* |
2 | | # Copyright 2016 Google Inc. |
3 | | # Copyright 2017 Red Hat, Inc. |
4 | | # |
5 | | # Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | # you may not use this file except in compliance with the License. |
7 | | # You may obtain a copy of the License at |
8 | | # |
9 | | # https://www.apache.org/licenses/LICENSE-2.0 |
10 | | # |
11 | | # Unless required by applicable law or agreed to in writing, software |
12 | | # distributed under the License is distributed on an "AS IS" BASIS, |
13 | | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | # See the License for the specific language governing permissions and |
15 | | # limitations under the License. |
16 | | # |
17 | | ################################################################################ |
18 | | */ |
19 | | |
20 | | #include <assert.h> |
21 | | #include <fcntl.h> |
22 | | #include <stdint.h> |
23 | | #include <sys/types.h> |
24 | | #include <unistd.h> |
25 | | #include <string.h> |
26 | | #include <stdlib.h> |
27 | | #include <stdbool.h> |
28 | | |
29 | | #include <gnutls/gnutls.h> |
30 | | #include "mem.h" |
31 | | #include "fuzzer.h" |
32 | | |
33 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
34 | 6.23k | { |
35 | 6.23k | int res; |
36 | 6.23k | gnutls_session_t session; |
37 | 6.23k | gnutls_certificate_credentials_t xcred; |
38 | 6.23k | struct mem_st memdata; |
39 | | |
40 | 6.23k | res = gnutls_init(&session, GNUTLS_CLIENT); |
41 | 6.23k | assert(res >= 0); |
42 | | |
43 | 6.23k | res = gnutls_certificate_allocate_credentials(&xcred); |
44 | 6.23k | assert(res >= 0); |
45 | 6.23k | res = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, xcred); |
46 | 6.23k | assert(res >= 0); |
47 | | |
48 | | /*res = gnutls_set_default_priority(session); */ |
49 | 6.23k | res = gnutls_priority_set_direct( |
50 | 6.23k | session, "NORMAL:+SIGN-EDDSA-ED448:" VERS_STR, NULL); |
51 | 6.23k | assert(res >= 0); |
52 | | |
53 | 6.23k | memdata.data = data; |
54 | 6.23k | memdata.size = size; |
55 | | |
56 | 6.23k | gnutls_transport_set_push_function(session, mem_push); |
57 | 6.23k | gnutls_transport_set_pull_function(session, mem_pull); |
58 | 6.23k | gnutls_transport_set_pull_timeout_function(session, mem_pull_timeout); |
59 | 6.23k | gnutls_transport_set_ptr(session, &memdata); |
60 | | |
61 | 173k | do { |
62 | 173k | res = gnutls_handshake(session); |
63 | 173k | } while (res < 0 && gnutls_error_is_fatal(res) == 0); |
64 | 6.23k | if (res >= 0) { |
65 | 0 | while (true) { |
66 | 0 | char buf[16384]; |
67 | 0 | res = gnutls_record_recv(session, buf, sizeof(buf)); |
68 | 0 | if (res <= 0) { |
69 | 0 | break; |
70 | 0 | } |
71 | 0 | } |
72 | 0 | } |
73 | | |
74 | 6.23k | gnutls_deinit(session); |
75 | 6.23k | gnutls_certificate_free_credentials(xcred); |
76 | 6.23k | return 0; |
77 | 6.23k | } |