From e3d621c66dd61797366c632e21d9edb80d9c669b Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 1 Nov 2022 11:13:40 +0100 Subject: [PATCH] Fixed: SEGV when using NETCONF get filter xpath and non-existent key * eg `select="/ex:table[ex:non-exist='a']` --- CHANGELOG.md | 2 ++ lib/src/clixon_xpath_eval.c | 16 ++++++++++++---- test/test_autocli_extension.sh | 4 ++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e634fcc..6d4d49b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,8 @@ Developers may need to change their code ### Corrected Bugs +* Fixed: SEGV when using NETCONF get filter xpath and non-existent key + * eg `select="/ex:table[ex:non-exist='a']` * Fixed: [CLI Show config JSON with multiple top-level elements is broken](https://github.com/clicon/clixon/issues/381) * Fixed: [Non-obvious behavior of clixon_snmp after snmpset command when transaction validation returns an error](https://github.com/clicon/clixon/issues/375) * Fixed by validating writes on ACTION instead of COMMIT since libnetsnmp seems not to accept commit errors diff --git a/lib/src/clixon_xpath_eval.c b/lib/src/clixon_xpath_eval.c index 6a5f4a2f..22067666 100644 --- a/lib/src/clixon_xpath_eval.c +++ b/lib/src/clixon_xpath_eval.c @@ -845,10 +845,18 @@ xp_relop(xp_ctx *xc1, case XO_EQ: if (s1 == NULL && s2 == NULL) xr->xc_bool = 1; - else if (s1 == NULL && strlen(s2) == 0) - xr->xc_bool = 1; - else if (strlen(s1) == 0 && s2 == NULL) - xr->xc_bool = 1; + if (s1 == NULL){ + if (strlen(s2) == 0) + xr->xc_bool = 1; + else + xr->xc_bool = 0; + } + else if (s2 == NULL){ + if (strlen(s1) == 0) + xr->xc_bool = 1; + else + xr->xc_bool = 0; + } else xr->xc_bool = (strcmp(s1, s2)==0); break; diff --git a/test/test_autocli_extension.sh b/test/test_autocli_extension.sh index c92b9ded..805636f5 100755 --- a/test/test_autocli_extension.sh +++ b/test/test_autocli_extension.sh @@ -133,6 +133,10 @@ EOF new "check datastore using netconf" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "$XML" + # Test not right context but could not find other test where it fits + new "negative test" + expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" + new "check datastore direct access" expectpart "$($clixon_util_datastore -d candidate -b $dir -y $fyang -Y ${YANG_INSTALLDIR} -Y $dir get /)" 0 "$XML"