diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt index d14e444e7e..8f409d071e 100644 --- a/tests/fuzz/CMakeLists.txt +++ b/tests/fuzz/CMakeLists.txt @@ -1,5 +1,5 @@ if(ENABLE_FUZZ_TARGETS) - set(fuzz_targets lys_parse_mem lyd_parse_mem_xml lyd_parse_mem_json lyd_parse_lyb lyd_parse_schema_mount_xml yang_parse_module) + set(fuzz_targets lys_parse_mem lyd_parse_mem_xml lyd_parse_mem_json lyd_parse_lyb lyd_parse_schema_mount_xml yang_parse_module lys_parse_mem_yin) if(FUZZER STREQUAL "AFL") foreach(target_name IN LISTS fuzz_targets) diff --git a/tests/fuzz/corpus/lys_parse_mem_yin/minimal.yin b/tests/fuzz/corpus/lys_parse_mem_yin/minimal.yin new file mode 100644 index 0000000000..e5f25b4911 --- /dev/null +++ b/tests/fuzz/corpus/lys_parse_mem_yin/minimal.yin @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/tests/fuzz/corpus/lys_parse_mem_yin/types.yin b/tests/fuzz/corpus/lys_parse_mem_yin/types.yin new file mode 100644 index 0000000000..7e51802904 --- /dev/null +++ b/tests/fuzz/corpus/lys_parse_mem_yin/types.yin @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/fuzz/corpus/lys_parse_mem_yin/xpath.yin b/tests/fuzz/corpus/lys_parse_mem_yin/xpath.yin new file mode 100644 index 0000000000..77dd845512 --- /dev/null +++ b/tests/fuzz/corpus/lys_parse_mem_yin/xpath.yin @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/fuzz/lys_parse_mem_yin.c b/tests/fuzz/lys_parse_mem_yin.c new file mode 100644 index 0000000000..4108ae7180 --- /dev/null +++ b/tests/fuzz/lys_parse_mem_yin.c @@ -0,0 +1,52 @@ +/** + * @file lys_parse_mem_yin.c + * @author OSS-Fuzz coverage pipeline + * @brief fuzzing harness for lys_parse_mem() with LYS_IN_YIN input format. + * + * Copyright (c) 2026 CESNET, z.s.p.o. + * + * This source code is licensed under BSD 3-Clause License (the "License"). + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + */ + +#include +#include +#include + +#include "libyang.h" +#include "tests_config.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(TESTS_SRC "/../modules", 0, &ctx); + if (err != LY_SUCCESS) { + return 0; + } + + data = malloc(len + 1); + if (data == NULL) { + ly_ctx_destroy(ctx); + return 0; + } + + memcpy(data, buf, len); + data[len] = 0; + + lys_parse_mem(ctx, data, LYS_IN_YIN, NULL); + ly_ctx_destroy(ctx); + free(data); + return 0; +} diff --git a/tests/fuzz/lys_parse_mem_yin.dict b/tests/fuzz/lys_parse_mem_yin.dict new file mode 100644 index 0000000000..5cb5952501 --- /dev/null +++ b/tests/fuzz/lys_parse_mem_yin.dict @@ -0,0 +1,64 @@ +"" +"" +"" +"" +"" +"" +"" +"" +"urn:ietf:params:xml:ns:yang:yin:1" +"yang:"