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 lyd_eval_xpath)

if(FUZZER STREQUAL "AFL")
foreach(target_name IN LISTS fuzz_targets)
Expand Down
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed01.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/c/l[k='a']/v
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed02.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/c/l[k='b']/v
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed03.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
count(/c/s)
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed04.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contains(/c/b,'true')
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed05.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
not(/c/l[k='zzz'])
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed06.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/c/s[.='x']
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed07.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
position() = 1
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed08.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/c/l[position() = 2]/k
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed09.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
string(/c/b)
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed10.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
number(/c/l[k='a']/v)
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed11.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/c/l[k='a']/v > 0
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed12.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/c/b = true()
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed13.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name(/c/*)
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed14.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/c/l[1]/k
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed15.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/c//v
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed16.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/c/s[2]
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed17.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sum(/c/l/v)
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed18.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
substring(/c/b, 1, 4)
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed19.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
starts-with(/c/s, 'x')
1 change: 1 addition & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/seed20.xp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/c/l[k='a' and v='1']
20 changes: 20 additions & 0 deletions tests/fuzz/corpus/lyd_eval_xpath/xpath.seeds
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/c/l[k='a']/v
/c/l[k='b']/v
count(/c/s)
contains(/c/b,'true')
not(/c/l[k='zzz'])
/c/s[.='x']
position() = 1
/c/l[position() = 2]/k
string(/c/b)
number(/c/l[k='a']/v)
/c/l[k='a']/v > 0
/c/b = true()
name(/c/*)
/c/l[1]/k
/c//v
/c/s[2]
sum(/c/l/v)
substring(/c/b, 1, 4)
starts-with(/c/s, 'x')
/c/l[k='a' and v='1']
78 changes: 78 additions & 0 deletions tests/fuzz/lyd_eval_xpath.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @file lyd_eval_xpath.c
* @author OSS-Fuzz coverage pipeline
* @brief fuzzing harness for lyd_eval_xpath() over a fixed data tree.
*
* The fuzzed input is used as an XPath expression evaluated against a small
* static data tree, exercising the XPath expression parser and evaluator
* (src/xpath.c, src/path.c) on attacker-controlled strings.
*
* 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"

static const char *schema =
"module fuzz-xp {namespace urn:tests:fuzz-xp;prefix x;"
"container c {list l {key k; leaf k {type string;} leaf v {type int32;}}"
"leaf-list s {type string;} leaf b {type boolean;}}}";
static const char *dataxml =
"<c xmlns=\"urn:tests:fuzz-xp\">"
"<l><k>a</k><v>1</v></l>"
"<l><k>b</k><v>2</v></l>"
"<s>x</s><s>y</s>"
"<b>true</b>"
"</c>";

int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len)
{
struct ly_ctx *ctx = NULL;
struct lyd_node *tree = NULL;
static bool log = false;
char *data = NULL;
ly_bool result = false;
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;
}

if (lys_parse_mem(ctx, schema, LYS_IN_YANG, NULL) != LY_SUCCESS) {
goto cleanup;
}
if (lyd_parse_data_mem(ctx, dataxml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree) != LY_SUCCESS) {
goto cleanup;
}

data = malloc(len + 1);
if (data == NULL) {
goto cleanup;
}
memcpy(data, buf, len);
data[len] = 0;

lyd_eval_xpath(tree, data, &result);

cleanup:
free(data);
lyd_free_all(tree);
ly_ctx_destroy(ctx);
return 0;
}
63 changes: 63 additions & 0 deletions tests/fuzz/lyd_eval_xpath.dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"//"
".."
"::"
"[position()="
"[last()]"
"ancestor::"
"attribute::"
"child::"
"descendant::"
"descendant-or-self::"
"following::"
"following-sibling::"
"namespace::*"
"parent::"
"preceding::"
"preceding-sibling::"
"self::"
"and"
"or"
"div"
"mod"
"!="
"<="
">="
"boolean("
"ceiling("
"concat("
"contains("
"count("
"current()"
"deref("
"derived-from("
"derived-from-or-self("
"enum-value("
"false()"
"floor("
"instanceof("
"lang("
"last()"
"local-name("
"name("
"namespace-uri("
"normalize-space("
"not("
"number("
"position()"
"re-match("
"round("
"starts-with("
"string("
"string-length("
"substring("
"substring-after("
"substring-before("
"sum("
"translate("
"true()"
"text()"
"comment()"
"node()"
"processing-instruction("
"@*"
"*"
Loading