From 044203039cebe3c05161f8f104a039d4744ca6d0 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 06:20:26 +0200 Subject: Adding upstream version 2.1.30. Signed-off-by: Daniel Baumann --- tests/fuzz/lys_parse_mem.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/fuzz/lys_parse_mem.c (limited to 'tests/fuzz/lys_parse_mem.c') diff --git a/tests/fuzz/lys_parse_mem.c b/tests/fuzz/lys_parse_mem.c new file mode 100644 index 0000000..02e0a62 --- /dev/null +++ b/tests/fuzz/lys_parse_mem.c @@ -0,0 +1,37 @@ +#include +#include +#include + +#include "libyang.h" + +int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len) +{ + struct ly_ctx *ctx = NULL; + static bool log = false; + char *data = NULL; + LY_ERR err; + + if (!log) { + ly_log_options(0); + log = true; + } + + err = ly_ctx_new(NULL, 0, &ctx); + if (err != LY_SUCCESS) { + fprintf(stderr, "Failed to create context\n"); + exit(EXIT_FAILURE); + } + + data = malloc(len + 1); + if (data == NULL) { + return 0; + } + + memcpy(data, buf, len); + data[len] = 0; + + lys_parse_mem(ctx, data, LYS_IN_YANG, NULL); + ly_ctx_destroy(ctx); + free(data); + return 0; +} -- cgit v1.2.3