fuzz_binary_message.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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_default.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_new_default();
  16. UA_Server *server = UA_Server_new(config);
  17. // we need to copy the message because it will be freed in the processing function
  18. UA_ByteString msg = UA_ByteString();
  19. UA_StatusCode retval = UA_ByteString_allocBuffer(&msg, size);
  20. if(retval != UA_STATUSCODE_GOOD)
  21. return (int)retval;
  22. memcpy(msg.data, data, size);
  23. UA_Server_processBinaryMessage(server, &c, &msg);
  24. // if we got an invalid chunk, the message is not deleted, so delete it here
  25. UA_ByteString_deleteMembers(&msg);
  26. UA_Server_delete(server);
  27. UA_ServerConfig_delete(config);
  28. UA_Connection_deleteMembers(&c);
  29. return 0;
  30. }