/src/gnutls/fuzz/gnutls_dn_parser_fuzzer.c
Line | Count | Source |
1 | | /* |
2 | | # Copyright 2016 Nikos Mavrogiannopoulos |
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 | | # https://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 | | */ |
18 | | |
19 | | #include <assert.h> |
20 | | #include <stdint.h> |
21 | | |
22 | | #include <gnutls/gnutls.h> |
23 | | #include <gnutls/x509.h> |
24 | | |
25 | | #include "fuzzer.h" |
26 | | |
27 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
28 | 11.3k | { |
29 | 11.3k | gnutls_datum_t out, raw; |
30 | 11.3k | gnutls_x509_dn_t dn; |
31 | 11.3k | int ret; |
32 | | |
33 | 11.3k | raw.data = (unsigned char *)data; |
34 | 11.3k | raw.size = size; |
35 | | |
36 | 11.3k | ret = gnutls_x509_dn_init(&dn); |
37 | 11.3k | assert(ret >= 0); |
38 | | |
39 | 11.3k | ret = gnutls_x509_dn_import(dn, &raw); |
40 | 11.3k | if (ret < 0) |
41 | 8.05k | goto cleanup; |
42 | | |
43 | | /* If properly loaded, try to re-export in string */ |
44 | 3.26k | ret = gnutls_x509_dn_get_str(dn, &out); |
45 | 3.26k | if (ret < 0) { |
46 | 64 | goto cleanup; |
47 | 64 | } |
48 | | |
49 | 3.20k | gnutls_free(out.data); |
50 | | |
51 | 11.3k | cleanup: |
52 | 11.3k | gnutls_x509_dn_deinit(dn); |
53 | 11.3k | return 0; |
54 | 3.20k | } |