fuzz_binary_message.c 1.0 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 "fuzz_common.h"
  5. UA_Connection c;
  6. UA_ServerConfig config;
  7. UA_Server *server = NULL;
  8. UA_ByteString msg;
  9. /*
  10. ** Main entry point. The fuzzer invokes this function with each
  11. ** fuzzed input.
  12. */
  13. int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  14. if (server == NULL) {
  15. c = createDummyConnection();
  16. config = UA_ServerConfig_standard;
  17. config.logger = UA_Log_Stdout;
  18. // no freeing needed, fuzzer is killed or shuts down due to exception
  19. server = UA_Server_new(config);
  20. }
  21. config.logger = UA_Log_Stdout;
  22. msg.length = size;
  23. msg.data = data;
  24. UA_Boolean reallocated = UA_FALSE;
  25. UA_StatusCode retval = UA_Connection_completeMessages(&c, &msg, &reallocated);
  26. if(retval == UA_STATUSCODE_GOOD && msg.length > 0)
  27. UA_Server_processBinaryMessage(server, &c, &msg);
  28. return 0;
  29. }