/src/libtasn1/fuzz/asn1_decode_simple_ber_fuzzer.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright(c) 2020 Free Software Foundation, Inc. |
3 | | * |
4 | | * This file is part of libtasn1. |
5 | | * |
6 | | * Libtasn1 is free software: you can redistribute it and/or modify |
7 | | * it under the terms of the GNU Lesser General Public License as published by |
8 | | * the Free Software Foundation, either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * Libtasn1 is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public License |
17 | | * along with libtasn1. If not, see <https://www.gnu.org/licenses/>. |
18 | | * |
19 | | * This fuzzer is testing asn1_array2tree()'s robustness with arbitrary |
20 | | * input data. |
21 | | */ |
22 | | |
23 | | #include <config.h> |
24 | | #include <assert.h> |
25 | | #include <stdlib.h> |
26 | | |
27 | | #include "libtasn1.h" |
28 | | #include "fuzzer.h" |
29 | | |
30 | | int |
31 | | LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) |
32 | 1.34k | { |
33 | 1.34k | int ret; |
34 | 1.34k | unsigned int ret_len; |
35 | 1.34k | unsigned char *str; |
36 | | |
37 | 1.34k | ret = |
38 | 1.34k | asn1_decode_simple_ber (ASN1_ETYPE_BIT_STRING, data, size, &str, &ret_len, |
39 | 1.34k | NULL); |
40 | 1.34k | if (ret == ASN1_SUCCESS) |
41 | 0 | { |
42 | 0 | free (str); |
43 | 0 | assert (ret_len <= size); |
44 | 0 | } |
45 | | |
46 | 1.34k | ret = |
47 | 1.34k | asn1_decode_simple_ber (ASN1_ETYPE_OCTET_STRING, data, size, &str, |
48 | 1.34k | &ret_len, NULL); |
49 | 1.34k | if (ret == ASN1_SUCCESS) |
50 | 266 | { |
51 | 266 | free (str); |
52 | 266 | assert (ret_len <= size); |
53 | 266 | } |
54 | | |
55 | 1.34k | return 0; |
56 | 1.34k | } |