From 60d28772171281eaccee12b0dbf6b36e23285b84 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Fri, 27 Nov 2026 08:34:53 +0000 Subject: [PATCH] OSS-Fuzz: ADd new fuzzer/corpus/dict targets xpath evaluation Signed-off-by: Arthur Chan --- tests/fuzz/CMakeLists.txt | 2 +- tests/fuzz/corpus/lyd_eval_xpath/seed01.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed02.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed03.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed04.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed05.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed06.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed07.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed08.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed09.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed10.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed11.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed12.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed13.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed14.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed15.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed16.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed17.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed18.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed19.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/seed20.xp | 1 + tests/fuzz/corpus/lyd_eval_xpath/xpath.seeds | 20 +++++ tests/fuzz/lyd_eval_xpath.c | 78 ++++++++++++++++++++ tests/fuzz/lyd_eval_xpath.dict | 63 ++++++++++++++++ 24 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed01.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed02.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed03.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed04.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed05.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed06.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed07.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed08.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed09.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed10.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed11.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed12.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed13.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed14.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed15.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed16.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed17.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed18.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed19.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/seed20.xp create mode 100644 tests/fuzz/corpus/lyd_eval_xpath/xpath.seeds create mode 100644 tests/fuzz/lyd_eval_xpath.c create mode 100644 tests/fuzz/lyd_eval_xpath.dict diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt index d14e444e7e..b45fd30b84 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 lyd_eval_xpath) if(FUZZER STREQUAL "AFL") foreach(target_name IN LISTS fuzz_targets) diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed01.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed01.xp new file mode 100644 index 0000000000..6277321ba1 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed01.xp @@ -0,0 +1 @@ +/c/l[k='a']/v \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed02.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed02.xp new file mode 100644 index 0000000000..5e9e5cbed9 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed02.xp @@ -0,0 +1 @@ +/c/l[k='b']/v \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed03.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed03.xp new file mode 100644 index 0000000000..26afc9c5ae --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed03.xp @@ -0,0 +1 @@ +count(/c/s) \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed04.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed04.xp new file mode 100644 index 0000000000..75f740c067 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed04.xp @@ -0,0 +1 @@ +contains(/c/b,'true') \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed05.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed05.xp new file mode 100644 index 0000000000..a52bddd886 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed05.xp @@ -0,0 +1 @@ +not(/c/l[k='zzz']) \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed06.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed06.xp new file mode 100644 index 0000000000..e5643c4c36 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed06.xp @@ -0,0 +1 @@ +/c/s[.='x'] \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed07.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed07.xp new file mode 100644 index 0000000000..b5ea4023e6 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed07.xp @@ -0,0 +1 @@ +position() = 1 \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed08.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed08.xp new file mode 100644 index 0000000000..456033c2c3 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed08.xp @@ -0,0 +1 @@ +/c/l[position() = 2]/k \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed09.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed09.xp new file mode 100644 index 0000000000..b1be59d407 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed09.xp @@ -0,0 +1 @@ +string(/c/b) \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed10.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed10.xp new file mode 100644 index 0000000000..b790b7dd69 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed10.xp @@ -0,0 +1 @@ +number(/c/l[k='a']/v) \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed11.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed11.xp new file mode 100644 index 0000000000..066915b605 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed11.xp @@ -0,0 +1 @@ +/c/l[k='a']/v > 0 \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed12.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed12.xp new file mode 100644 index 0000000000..1b74d95f49 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed12.xp @@ -0,0 +1 @@ +/c/b = true() \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed13.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed13.xp new file mode 100644 index 0000000000..96a53a9eeb --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed13.xp @@ -0,0 +1 @@ +name(/c/*) \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed14.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed14.xp new file mode 100644 index 0000000000..907ede7f04 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed14.xp @@ -0,0 +1 @@ +/c/l[1]/k \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed15.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed15.xp new file mode 100644 index 0000000000..32da128e3b --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed15.xp @@ -0,0 +1 @@ +/c//v \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed16.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed16.xp new file mode 100644 index 0000000000..cba6ab0510 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed16.xp @@ -0,0 +1 @@ +/c/s[2] \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed17.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed17.xp new file mode 100644 index 0000000000..5b56f3c76e --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed17.xp @@ -0,0 +1 @@ +sum(/c/l/v) \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed18.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed18.xp new file mode 100644 index 0000000000..b0c1da3d8f --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed18.xp @@ -0,0 +1 @@ +substring(/c/b, 1, 4) \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed19.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed19.xp new file mode 100644 index 0000000000..abdee78d4a --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed19.xp @@ -0,0 +1 @@ +starts-with(/c/s, 'x') \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/seed20.xp b/tests/fuzz/corpus/lyd_eval_xpath/seed20.xp new file mode 100644 index 0000000000..8125b1a440 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/seed20.xp @@ -0,0 +1 @@ +/c/l[k='a' and v='1'] \ No newline at end of file diff --git a/tests/fuzz/corpus/lyd_eval_xpath/xpath.seeds b/tests/fuzz/corpus/lyd_eval_xpath/xpath.seeds new file mode 100644 index 0000000000..f591f62b30 --- /dev/null +++ b/tests/fuzz/corpus/lyd_eval_xpath/xpath.seeds @@ -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'] diff --git a/tests/fuzz/lyd_eval_xpath.c b/tests/fuzz/lyd_eval_xpath.c new file mode 100644 index 0000000000..8f45ae5e05 --- /dev/null +++ b/tests/fuzz/lyd_eval_xpath.c @@ -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 +#include +#include + +#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 = + "" + "a1" + "b2" + "xy" + "true" + ""; + +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; +} diff --git a/tests/fuzz/lyd_eval_xpath.dict b/tests/fuzz/lyd_eval_xpath.dict new file mode 100644 index 0000000000..fbcc8e56a9 --- /dev/null +++ b/tests/fuzz/lyd_eval_xpath.dict @@ -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(" +"@*" +"*"