/src/p11-kit/fuzz/persist_fuzzer.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2026, David Korczynski. |
3 | | * |
4 | | * All rights reserved. |
5 | | * |
6 | | * Redistribution and use in source and binary forms, with or without |
7 | | * modification, are permitted provided that the following conditions |
8 | | * are met: |
9 | | * |
10 | | * * Redistributions of source code must retain the above |
11 | | * copyright notice, this list of conditions and the |
12 | | * following disclaimer. |
13 | | * * Redistributions in binary form must reproduce the |
14 | | * above copyright notice, this list of conditions and |
15 | | * the following disclaimer in the documentation and/or |
16 | | * other materials provided with the distribution. |
17 | | * * The names of contributors to this software may not be |
18 | | * used to endorse or promote products derived from this |
19 | | * software without specific prior written permission. |
20 | | * |
21 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
22 | | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
23 | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
24 | | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
25 | | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
26 | | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
27 | | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
28 | | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
29 | | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
30 | | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
31 | | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
32 | | * DAMAGE. |
33 | | * |
34 | | */ |
35 | | |
36 | | #include "config.h" |
37 | | #include "test.h" |
38 | | |
39 | | #include "fuzz/fuzz.h" |
40 | | #include "asn1.h" |
41 | | #include "trust/parser.h" |
42 | | |
43 | | #include <stdlib.h> |
44 | | |
45 | | #ifdef __cplusplus |
46 | | extern "C" |
47 | | #endif |
48 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
49 | 3.35k | { |
50 | 3.35k | p11_parser *parser; |
51 | | |
52 | 3.35k | if (size < 1) |
53 | 0 | return 0; |
54 | | |
55 | 3.35k | parser = p11_parser_new(NULL); |
56 | 3.35k | if (!parser) |
57 | 0 | return 0; |
58 | | |
59 | | /* Register all format handlers so the parser auto-detects the format. |
60 | | * This exercises PEM, DER (X.509), and p11-kit persist format parsing. */ |
61 | 3.35k | p11_parser_formats(parser, |
62 | 3.35k | p11_parser_format_x509, |
63 | 3.35k | p11_parser_format_pem, |
64 | 3.35k | p11_parser_format_persist, |
65 | 3.35k | NULL); |
66 | | |
67 | 3.35k | p11_parse_memory(parser, "fuzz-input", P11_PARSE_FLAG_NONE, |
68 | 3.35k | data, size); |
69 | | |
70 | 3.35k | p11_parser_free(parser); |
71 | | |
72 | 3.35k | return 0; |
73 | 3.35k | } |