/src/strongswan/fuzz/fuzz_pa_tnc.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2018 Andreas Steffen |
3 | | * |
4 | | * Copyright (C) secunet Security Networks AG |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify it |
7 | | * under the terms of the GNU General Public License as published by the |
8 | | * Free Software Foundation; either version 2 of the License, or (at your |
9 | | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, but |
12 | | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
13 | | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 | | * for more details. |
15 | | */ |
16 | | |
17 | | #include <library.h> |
18 | | #include <imcv.h> |
19 | | #include <pa_tnc/pa_tnc_msg.h> |
20 | | #include <ietf/ietf_attr_pa_tnc_error.h> |
21 | | #include <utils/debug.h> |
22 | | |
23 | | int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) |
24 | 5.25k | { |
25 | 5.25k | pa_tnc_msg_t *msg; |
26 | 5.25k | pa_tnc_attr_t *attr; |
27 | 5.25k | ietf_attr_pa_tnc_error_t *error; |
28 | 5.25k | linked_list_t *non_fatal_types; |
29 | 5.25k | enumerator_t *enumerator; |
30 | 5.25k | chunk_t chunk; |
31 | | |
32 | 5.25k | dbg_default_set_level(-1); |
33 | 5.25k | library_init(NULL, "fuzz_pa_tnc"); |
34 | 5.25k | libimcv_init(FALSE); |
35 | | |
36 | 5.25k | chunk = chunk_create((u_char*)buf, len); |
37 | | |
38 | | /* Parse incoming PA-TNC message */ |
39 | 5.25k | msg = pa_tnc_msg_create_from_data(chunk); |
40 | 5.25k | if (msg->process(msg) == SUCCESS) |
41 | 2.26k | { |
42 | 2.26k | non_fatal_types = linked_list_create(); |
43 | 2.26k | msg->process_ietf_std_errors(msg, non_fatal_types); |
44 | 2.26k | non_fatal_types->destroy(non_fatal_types); |
45 | 2.26k | } |
46 | | |
47 | | /* enumerate correctly decoded attributes */ |
48 | 5.25k | enumerator = msg->create_attribute_enumerator(msg); |
49 | 46.0k | while (enumerator->enumerate(enumerator, &attr)) |
50 | 40.8k | { |
51 | 40.8k | attr->get_noskip_flag(attr); |
52 | 40.8k | } |
53 | 5.25k | enumerator->destroy(enumerator); |
54 | | |
55 | | /* enumerate errors detected while parsing PA-TNC message and attributes */ |
56 | 5.25k | enumerator = msg->create_error_enumerator(msg); |
57 | 8.23k | while (enumerator->enumerate(enumerator, &attr)) |
58 | 2.98k | { |
59 | 2.98k | error = (ietf_attr_pa_tnc_error_t*)attr; |
60 | 2.98k | error->get_error_code(error); |
61 | 2.98k | } |
62 | 5.25k | enumerator->destroy(enumerator); |
63 | | |
64 | 5.25k | msg->destroy(msg); |
65 | | |
66 | 5.25k | libimcv_deinit(); |
67 | 5.25k | library_deinit(); |
68 | 5.25k | return 0; |
69 | 5.25k | } |