fuzz_binary_message.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "ua_server_internal.h"
  5. #include "ua_config_standard.h"
  6. #include "ua_log_stdout.h"
  7. #include "ua_plugin_log.h"
  8. #include "testing_networklayers.h"
  9. /*
  10. ** Main entry point. The fuzzer invokes this function with each
  11. ** fuzzed input.
  12. */
  13. extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  14. UA_Connection c = createDummyConnection();
  15. UA_ServerConfig config = UA_ServerConfig_standard;
  16. config.logger = UA_Log_Stdout;
  17. UA_Server *server = UA_Server_new(config);
  18. UA_ByteString msg = {
  19. size, //length
  20. const_cast<UA_Byte*>(data) //data
  21. };
  22. config.logger = UA_Log_Stdout;
  23. UA_Boolean reallocated = UA_FALSE;
  24. UA_StatusCode retval = UA_Connection_completeChunks(&c, &msg, &reallocated);
  25. if(retval == UA_STATUSCODE_GOOD && msg.length > 0)
  26. UA_Server_processBinaryMessage(server, &c, &msg);
  27. UA_Server_delete(server);
  28. UA_Connection_deleteMembers(&c);
  29. return 0;
  30. }