/src/opensc/src/tests/fuzzing/fuzz_pkcs11_uri.c
Line | Count | Source |
1 | | /* |
2 | | * fuzz_pkcs11_uri.c: Fuzz target for PKCS #11 URI parser |
3 | | * |
4 | | * Copyright (C) 2025 Red Hat, Inc. |
5 | | * |
6 | | * Author: Veronika Hanulikova <vhanulik@redhat.com> |
7 | | * |
8 | | * This library is free software; you can redistribute it and/or |
9 | | * modify it under the terms of the GNU Lesser General Public |
10 | | * License as published by the Free Software Foundation; either |
11 | | * version 2.1 of the License, or (at your option) any later version. |
12 | | * |
13 | | * This library is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | | * Lesser General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU General Public License |
19 | | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #ifdef HAVE_CONFIG_H |
23 | | #include "config.h" |
24 | | #endif |
25 | | |
26 | | #include <stdint.h> |
27 | | #include <stdio.h> |
28 | | #include <stdlib.h> |
29 | | #include <string.h> |
30 | | #include <tools/pkcs11_uri.h> |
31 | | |
32 | | #undef stderr |
33 | | #define stderr stdout |
34 | | |
35 | | int |
36 | | LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
37 | 427 | { |
38 | 427 | char *input_string = NULL; |
39 | 427 | struct pkcs11_uri *uri = NULL; |
40 | 427 | if (Size == 0) |
41 | 0 | return 0; |
42 | 427 | if ((input_string = malloc(Size + 1)) == NULL) |
43 | 0 | return 0; |
44 | 427 | memcpy(input_string, Data, Size); |
45 | 427 | input_string[Size] = 0; |
46 | | |
47 | 427 | if ((uri = pkcs11_uri_new()) == NULL) { |
48 | 0 | free(input_string); |
49 | 0 | return 0; |
50 | 0 | } |
51 | 427 | parse_pkcs11_uri(input_string, uri); |
52 | | |
53 | 427 | pkcs11_uri_free(uri); |
54 | 427 | free(input_string); |
55 | 427 | return 0; |
56 | 427 | } |