fuzz_pa_tnc.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include <library.h>
  16. #include <imcv.h>
  17. #include <pa_tnc/pa_tnc_msg.h>
  18. #include <ietf/ietf_attr_pa_tnc_error.h>
  19. #include <utils/debug.h>
  20. int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
  21. {
  22. pa_tnc_msg_t *msg;
  23. pa_tnc_attr_t *attr;
  24. ietf_attr_pa_tnc_error_t *error;
  25. linked_list_t *non_fatal_types;
  26. enumerator_t *enumerator;
  27. chunk_t chunk;
  28. dbg_default_set_level(-1);
  29. library_init(NULL, "fuzz_pa_tnc");
  30. plugin_loader_add_plugindirs(PLUGINDIR, PLUGINS);
  31. if (!lib->plugins->load(lib->plugins, PLUGINS))
  32. {
  33. return 1;
  34. }
  35. libimcv_init(FALSE);
  36. chunk = chunk_create((u_char*)buf, len);
  37. /* Parse incoming PA-TNC message */
  38. msg = pa_tnc_msg_create_from_data(chunk);
  39. if (msg->process(msg) == SUCCESS)
  40. {
  41. non_fatal_types = linked_list_create();
  42. msg->process_ietf_std_errors(msg, non_fatal_types);
  43. non_fatal_types->destroy(non_fatal_types);
  44. }
  45. /* enumerate correctly decoded attributes */
  46. enumerator = msg->create_attribute_enumerator(msg);
  47. while (enumerator->enumerate(enumerator, &attr))
  48. {
  49. attr->get_noskip_flag(attr);
  50. }
  51. enumerator->destroy(enumerator);
  52. /* enumerate errors detected while parsing PA-TNC message and attributes */
  53. enumerator = msg->create_error_enumerator(msg);
  54. while (enumerator->enumerate(enumerator, &attr))
  55. {
  56. error = (ietf_attr_pa_tnc_error_t*)attr;
  57. error->get_error_code(error);
  58. }
  59. enumerator->destroy(enumerator);
  60. msg->destroy(msg);
  61. libimcv_deinit();
  62. lib->plugins->unload(lib->plugins);
  63. library_deinit();
  64. return 0;
  65. }