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