From 61869c8d4490388d6fb312483c59a8186eec6524 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sat, 27 Oct 2018 17:06:08 +0200 Subject: [PATCH] Fixed https://github.com/clicon/clixon/issues/46 Issue with empty values in leaf-list Thanks achernavin22 --- CHANGELOG.md | 2 ++ apps/restconf/restconf_stream.c | 2 +- lib/src/clixon_xml_sort.c | 21 +++++++++++++++------ test/test_list.sh | 8 +++----- test/test_yang.sh | 12 ++++++++++++ 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0099111..34ad35a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,8 @@ * Added -l option for clixon_backend for directing syslog to stderr or stdout if running in foreground ### Corrected Bugs +* Fixed https://github.com/clicon/clixon/issues/46 Issue with empty values in leaf-list + * Thanks achernavin22 * Identity without any identityref:s caused SEGV * Memory error in backend transaction revert * Set dir /www-data with www-data as owner, see https://github.com/clicon/clixon/issues/37 diff --git a/apps/restconf/restconf_stream.c b/apps/restconf/restconf_stream.c index e2c3615a..2231d4a4 100644 --- a/apps/restconf/restconf_stream.c +++ b/apps/restconf/restconf_stream.c @@ -99,7 +99,7 @@ restconf_stream_cb(int s, struct clicon_msg *reply = NULL; cxobj *xtop = NULL; /* top xml */ cxobj *xn; /* notification xml */ - cbuf *cb; + cbuf *cb = NULL; int pretty = 0; /* XXX should be via arg */ clicon_debug(1, "%s", __FUNCTION__); diff --git a/lib/src/clixon_xml_sort.c b/lib/src/clixon_xml_sort.c index e3aa4b23..27842b6a 100644 --- a/lib/src/clixon_xml_sort.c +++ b/lib/src/clixon_xml_sort.c @@ -74,12 +74,13 @@ int xml_child_sort = 1; -/*! Given an XML object and a child name, return yang stmt of child +/*! Given a child name and an XML object, return yang stmt of child * If no xml parent, find root yang stmt matching name - * @param[in] name Name of child + * @param[in] x Child * @param[in] xp XML parent, can be NULL. * @param[in] yspec Yang specification (top level) * @param[out] yresult Pointer to yang stmt of result, or NULL, if not found + * @note special rule for rpc, ie ,look for top "foo" node. */ int xml_child_spec(char *name, @@ -108,6 +109,7 @@ xml_child_spec(char *name, * @retval >0 if arg1 is greater than arg2 * @note args are pointer ot pointers, to fit into qsort cmp function * @see xml_cmp1 Similar, but for one object + * @note empty value/NULL is smallest value */ int xml_cmp(const void* arg1, @@ -144,7 +146,12 @@ xml_cmp(const void* arg1, return 0; /* Ordered by user: maintain existing order */ switch (y1->ys_keyword){ case Y_LEAF_LIST: /* Match with name and value */ - equal = strcmp(xml_body(x1), xml_body(x2)); + if ((b1 = xml_body(x1)) == NULL) + equal = -1; + else if ((b2 = xml_body(x2)) == NULL) + equal = 1; + else + equal = strcmp(b1, b2); break; case Y_LIST: /* Match with key values * Use Y_LIST cache (see struct yang_stmt) @@ -168,7 +175,7 @@ xml_cmp(const void* arg1, } /*! Compare xml object - * @param[in] yangi Yang order + * @param[in] yangi Yang order * @param[in] keynr Length of keyvec/keyval vector when applicable * @param[in] keyvec Array of of yang key identifiers * @param[in] keyval Array of of yang key values @@ -203,8 +210,10 @@ xml_cmp1(cxobj *x, case Y_LEAF_LIST: /* Match with name and value */ if (userorder && yang_find((yang_node*)y, Y_ORDERED_BY, "user") != NULL) *userorder=1; - b=xml_body(x); - match = strcmp(keyval[0], b); + if ((b=xml_body(x)) == NULL) + match = 1; + else + match = strcmp(keyval[0], b); break; case Y_LIST: /* Match with array of key values */ if (userorder && yang_find((yang_node*)y, Y_ORDERED_BY, "user") != NULL) diff --git a/test/test_list.sh b/test/test_list.sh index ed04b36a..048a18f3 100755 --- a/test/test_list.sh +++ b/test/test_list.sh @@ -5,8 +5,6 @@ APPNAME=example # include err() and new() functions and creates $dir . ./lib.sh - - cfg=$dir/conf_yang.xml fyang=$dir/test.yang @@ -91,8 +89,8 @@ expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "replace]]>]]>" "^]]>]]>$" -exit # NYI - +# NYI +if false; then new "minmax: validate should fail" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" @@ -119,7 +117,7 @@ expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" - +fi # NYI # kill backend diff --git a/test/test_yang.sh b/test/test_yang.sh index d23ddfcc..f54e03bc 100755 --- a/test/test_yang.sh +++ b/test/test_yang.sh @@ -114,6 +114,18 @@ fi new "cli defined extension" expectfn "$clixon_cli -1f $cfg -y $fyang show version" 0 "3." +new "empty values in leaf-list" +expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "a]]>]]>" "^]]>]]>$" + +new "empty values in leaf-list2" +expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" + +new "netconf get config" +expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^a]]>]]>$" + +new "netconf discard-changes" +expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" + new "cli not defined extension" # This text yields an error, but the test cannot detect the error message yet #expectfn "$clixon_cli -1f $cfg -y $fyangerr show version" 0 "Yang error: Extension ex:not-defined not found"