/src/strongswan/fuzz/fuzz_pa_tnc.c
Line | Count | Source (jump to first uncovered line) |
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.26k | { |
25 | 5.26k | pa_tnc_msg_t *msg; |
26 | 5.26k | pa_tnc_attr_t *attr; |
27 | 5.26k | ietf_attr_pa_tnc_error_t *error; |
28 | 5.26k | linked_list_t *non_fatal_types; |
29 | 5.26k | enumerator_t *enumerator; |
30 | 5.26k | chunk_t chunk; |
31 | | |
32 | 5.26k | dbg_default_set_level(-1); |
33 | 5.26k | library_init(NULL, "fuzz_pa_tnc"); |
34 | 5.26k | plugin_loader_add_plugindirs(PLUGINDIR, PLUGINS); |
35 | 5.26k | if (!lib->plugins->load(lib->plugins, PLUGINS)) |
36 | 0 | { |
37 | 0 | return 1; |
38 | 0 | } |
39 | 5.26k | libimcv_init(FALSE); |
40 | 5.26k | chunk = chunk_create((u_char*)buf, len); |
41 | | |
42 | | /* Parse incoming PA-TNC message */ |
43 | 5.26k | msg = pa_tnc_msg_create_from_data(chunk); |
44 | 5.26k | if (msg->process(msg) == SUCCESS) |
45 | 2.30k | { |
46 | 2.30k | non_fatal_types = linked_list_create(); |
47 | 2.30k | msg->process_ietf_std_errors(msg, non_fatal_types); |
48 | 2.30k | non_fatal_types->destroy(non_fatal_types); |
49 | 2.30k | } |
50 | | |
51 | | /* enumerate correctly decoded attributes */ |
52 | 5.26k | enumerator = msg->create_attribute_enumerator(msg); |
53 | 57.1k | while (enumerator->enumerate(enumerator, &attr)) |
54 | 51.9k | { |
55 | 51.9k | attr->get_noskip_flag(attr); |
56 | 51.9k | } |
57 | 5.26k | enumerator->destroy(enumerator); |
58 | | |
59 | | /* enumerate errors detected while parsing PA-TNC message and attributes */ |
60 | 5.26k | enumerator = msg->create_error_enumerator(msg); |
61 | 8.22k | while (enumerator->enumerate(enumerator, &attr)) |
62 | 2.95k | { |
63 | 2.95k | error = (ietf_attr_pa_tnc_error_t*)attr; |
64 | 2.95k | error->get_error_code(error); |
65 | 2.95k | } |
66 | 5.26k | enumerator->destroy(enumerator); |
67 | | |
68 | 5.26k | msg->destroy(msg); |
69 | | |
70 | 5.26k | libimcv_deinit(); |
71 | 5.26k | lib->plugins->unload(lib->plugins); |
72 | 5.26k | library_deinit(); |
73 | 5.26k | return 0; |
74 | 5.26k | } |