From f5209b1fab3f6f7482d7d621a930e966ef024ce5 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 27 Jan 2020 22:11:35 +0100 Subject: [PATCH] * Fixed: Validation of user state data led to wrong validation, if state relied on config data, eg leafref/must/when etc. * Fixed: No revision in yang module led to errors in validation of state data --- CHANGELOG.md | 3 ++- apps/backend/backend_plugin.c | 24 ++++++++++++++---------- lib/src/clixon_yang_type.c | 3 ++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06639c54..bbba6c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,11 @@ ## 4.3.1 (Expected: January 2020) ### Corrected Bugs +* Fixed: Validation of user state data led to wrong validation, if state relied on config data, eg leafref/must/when etc. +* Fixed: No revision in yang module led to errors in validation of state data * Fixed: Leafref validation did not cover case of when the "path" statement is declared within a typedef, only if it was declared in the data part directly under leaf. * Fixed: Yang `must` xpath statements containing prefixes stopped working due to namespace context updates - ## 4.3.0 (1 January 2020) There were several issues with multiple namespaces with augmented yangs in 4.2 that have been fixed in 4.3. Some other highlights include: several issues with XPaths including "canonical namespace context" support, a reorganization of the YANG files shipped with the release, and a wildchar in the CLICON_MODE variable. diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c index 1dde1a65..19da9990 100644 --- a/apps/backend/backend_plugin.c +++ b/apps/backend/backend_plugin.c @@ -116,6 +116,7 @@ clixon_plugin_statedata(clicon_handle h, clixon_plugin *cp = NULL; plgstatedata_t *fn; /* Plugin statedata fn */ cbuf *cberr = NULL; + int i = 0; while ((cp = clixon_plugin_each(h, cp)) != NULL) { if ((fn = cp->cp_api.ca_statedata) == NULL) @@ -124,14 +125,25 @@ clixon_plugin_statedata(clicon_handle h, goto done; if (fn(h, nsc, xpath, x) < 0) goto fail; /* Dont quit here on user callbacks */ + i++; /* indicates that new state data is added */ if (xml_apply(x, CX_ELMNT, xml_spec_populate, yspec) < 0) goto done; + if ((ret = netconf_trymerge(x, yspec, xret)) < 0) + goto done; + if (ret == 0) + goto fail; + if (x){ + xml_free(x); + x = NULL; + } + } + if (i){ /* Check XML from state callback by validating it. return internal * error with error cause */ - if ((ret = xml_yang_validate_all_top(h, x, &xerr)) < 0) + if ((ret = xml_yang_validate_all_top(h, *xret, &xerr)) < 0) goto done; - if (ret > 0 && (ret = xml_yang_validate_add(h, x, &xerr)) < 0) + if (ret > 0 && (ret = xml_yang_validate_add(h, *xret, &xerr)) < 0) goto done; if (ret == 0){ cxobj *xe; @@ -164,14 +176,6 @@ clixon_plugin_statedata(clicon_handle h, cbuf_free(ccc); } #endif - if ((ret = netconf_trymerge(x, yspec, xret)) < 0) - goto done; - if (ret == 0) - goto fail; - if (x){ - xml_free(x); - x = NULL; - } } retval = 1; done: diff --git a/lib/src/clixon_yang_type.c b/lib/src/clixon_yang_type.c index 9016cdc3..0cd50346 100644 --- a/lib/src/clixon_yang_type.c +++ b/lib/src/clixon_yang_type.c @@ -1104,7 +1104,8 @@ ys_cv_validate(clicon_handle h, /* Note restype can be NULL here for example with unresolved hardcoded uuid */ if (restype && strcmp(restype, "union") == 0){ assert(cvtype == CGV_REST); - val = cv_string_get(cv); + if ((val = cv_string_get(cv)) == NULL) + val = ""; if ((retval2 = ys_cv_validate_union(h, ys, reason, yrestype, origtype, val)) < 0) goto done; retval = retval2; /* invalid (0) with latest reason or valid 1 */