From cd07912073c951b4bbb871ed2653af1be2cfc714 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 11:55:11 +0200 Subject: Adding upstream version 2.1.30. Signed-off-by: Daniel Baumann --- tests/fuzz/yang_parse_module.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/fuzz/yang_parse_module.c (limited to 'tests/fuzz/yang_parse_module.c') diff --git a/tests/fuzz/yang_parse_module.c b/tests/fuzz/yang_parse_module.c new file mode 100644 index 0000000..f420966 --- /dev/null +++ b/tests/fuzz/yang_parse_module.c @@ -0,0 +1,39 @@ +#include +#include +#include + +#include "libyang.h" + +int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len) +{ + struct lys_module *mod; + uint8_t *data = NULL; + struct ly_ctx *ctx = NULL; + static bool log = false; + 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 new context\n"); + return 0; + } + + data = malloc(len + 1); + if (data == NULL) { + fprintf(stderr, "Out of memory\n"); + return 0; + } + memcpy(data, buf, len); + data[len] = 0; + + lys_parse_mem(ctx, (const char *)data, LYS_IN_YANG, &mod); + + free(data); + ly_ctx_destroy(ctx); + return 0; +} -- cgit v1.2.3