Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 12 additions & 0 deletions tests/fuzz/corpus/lys_parse_mem_yin/minimal.yin
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module name="fuzz-yin-min"
xmlns="urn:ietf:params:xml:ns:yang:yin:1"
xmlns:fm="urn:example:fuzz-yin-min">
<namespace uri="urn:example:fuzz-yin-min"/>
<prefix value="fm"/>
<container name="top">
<leaf name="s">
<type value="string"/>
</leaf>
</container>
</module>
32 changes: 32 additions & 0 deletions tests/fuzz/corpus/lys_parse_mem_yin/types.yin
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<module name="fuzz-yin-types"
xmlns="urn:ietf:params:xml:ns:yang:yin:1"
xmlns:ft="urn:example:fuzz-yin-types">
<namespace uri="urn:example:fuzz-yin-types"/>
<prefix value="ft"/>
<typedef name="pct">
<type value="uint8"/>
<range value="0..100"/>
</typedef>
<list name="l">
<key value="id"/>
<leaf name="id">
<type value="string"/>
</leaf>
<leaf-list name="vals">
<type value="pct"/>
</leaf-list>
</list>
<leaf name="e">
<type value="enumeration">
<enum name="a"/>
<enum name="b"/>
</type>
</leaf>
<leaf name="b">
<type value="bits">
<bit name="zero"/>
<bit name="one"/>
</type>
</leaf>
</module>
23 changes: 23 additions & 0 deletions tests/fuzz/corpus/lys_parse_mem_yin/xpath.yin
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<module name="fuzz-yin-xpath"
xmlns="urn:ietf:params:xml:ns:yang:yin:1"
xmlns:fx="urn:example:fuzz-yin-xpath">
<namespace uri="urn:example:fuzz-yin-xpath"/>
<prefix value="fx"/>
<leaf name="enabled">
<type value="boolean"/>
</leaf>
<container name="c">
<must condition="../enabled = &apos;true&apos;"/>
<uses name="g"/>
</container>
<grouping name="g">
<leaf name="gl">
<type value="int32"/>
</leaf>
</grouping>
<leaf name="w">
<type value="empty"/>
<when condition="../enabled = &apos;true&apos;"/>
</leaf>
</module>
52 changes: 52 additions & 0 deletions tests/fuzz/lys_parse_mem_yin.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#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;
}
64 changes: 64 additions & 0 deletions tests/fuzz/lys_parse_mem_yin.dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"<module name=\""
"</module>"
"<submodule name=\""
"<namespace uri=\""
"<prefix value=\""
"<belongs-to module=\""
"<import module=\""
"<revision-date value=\""
"<include module=\""
"<revision value=\""
"<container name=\""
"</container>"
"<leaf name=\""
"</leaf>"
"<leaf-list name=\""
"</leaf-list>"
"<list name=\""
"</list>"
"<key value=\""
"<unique tag=\""
"<choice name=\""
"<case name=\""
"<anyxml name=\""
"<anydata name=\""
"<grouping name=\""
"<uses name=\""
"<refine value=\""
"<augment value=\""
"<typedef name=\""
"<type value=\""
"<default value=\""
"<mandatory value=\""
"<min-elements value=\""
"<max-elements value=\""
"<ordered-by value=\""
"<config value=\""
"<status value=\""
"<description text=\""
"<reference uri=\""
"<must condition=\""
"<when condition=\""
"<pattern value=\""
"<range value=\""
"<length value=\""
"<fraction-digits value=\""
"<enum name=\""
"<bit name=\""
"<position value=\""
"<base name=\""
"<extension name=\""
"<feature name=\""
"<if-feature name=\""
"<identity name=\""
"<notification name=\""
"<rpc name=\""
"<input>"
"<output>"
"<action name=\""
"<error-message value=\""
"<error-app-tag value=\""
"xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"urn:ietf:params:xml:ns:yang:yin:1"
"yang:"
Loading