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