From 60c9172d21735ddcd74ca1c75b7779d7501ce468 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 24 May 2021 21:05:06 +0200 Subject: [PATCH] Fixed: [Using YANG union with decimal64 and string leads to regexp match fail #226](https://github.com/clicon/clixon/issues/226) --- CHANGELOG.md | 1 + lib/src/clixon_yang.c | 2 +- lib/src/clixon_yang_type.c | 35 ++++++++++++++++++++++------------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6232e3c1..9162f6ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,7 @@ Users may have to change how they access the system ### Corrected Bugs +* Fixed: [Using YANG union with decimal64 and string leads to regexp match fail #226](https://github.com/clicon/clixon/issues/226) * Fixed: [xpath function count did not work properly #224](https://github.com/clicon/clixon/issues/224) * Fixed: RESTCONF Native: Failed binding of socket in network namespace caused process zombie * Fixed problems with XPATH composite operations and functions in netconf get/get-config operations. diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 25ff4981..69f37a45 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -2885,7 +2885,7 @@ yang_abs_schema_nodeid(yang_stmt *yn, /* If p0 is NULL an entry will be: [i0] which needs to be transformed to [NULL:i0] */ cv = NULL; while ((cv = cvec_each(nodeid_cvv, cv)) != NULL){ - if (cv_type_get(cv) != CGV_STRING) + if (cv_type_get(cv) != CGV_STRING) cv_type_set(cv, CGV_STRING); if ((str = cv_string_get(cv)) == NULL || !strlen(str)){ if (cv_string_set(cv, cv_name_get(cv)) < 0){ diff --git a/lib/src/clixon_yang_type.c b/lib/src/clixon_yang_type.c index 738269c4..a2b5294b 100644 --- a/lib/src/clixon_yang_type.c +++ b/lib/src/clixon_yang_type.c @@ -743,10 +743,15 @@ static int ys_cv_validate_union(clicon_handle h,yang_stmt *ys, char **reason, yang_stmt *yrestype, char *type, char *val, yang_stmt **ysubp); /*! - * @param[out] reason If given and return val is 0, contains a malloced string - * @retval -1 Error (fatal), with errno set to indicate error - * @retval 0 Validation not OK, malloced reason is returned. Free reason with free() - * @retval 1 Validation OK + * @param[in] h Clixon handle + * @param[in] ys Yang statement (union) + * @param[out] reason If given, and return value is 0, contains malloced string + * param[in] yt One of the types in the union + * param[in] type Original type + * @param[in] val Value to match + * @retval -1 Error (fatal), with errno set to indicate error + * @retval 0 Validation not OK, malloced reason is returned. Free reason with free() + * @retval 1 Validation OK */ static int ys_cv_validate_union_one(clicon_handle h, @@ -792,6 +797,8 @@ ys_cv_validate_union_one(clicon_handle h, clicon_err(OE_UNIX, errno, "cv_new"); goto done; } + if (cvtype == CGV_DEC64) + cv_dec64_n_set(cvt, fraction); if (val == NULL){ /* Fail validation on NULL */ retval = 0; goto done; @@ -828,21 +835,23 @@ ys_cv_validate_union_one(clicon_handle h, } /*! Validate union - * @param[in] h Clixon handle - * @param[in] ys Yang statement (union) - * @param[out] reason If given, and return value is 0, contains malloced string - * @param[in] val Value to match - * @param[out] ysubp Sub-type of ys that matches val - * @retval -1 Error (fatal), with errno set to indicate error - * @retval 0 Validation not OK, malloced reason is returned. Free reason with free() - * @retval 1 Validation OK + * @param[in] h Clixon handle + * @param[in] ys Yang statement (union) + * @param[out] reason If given, and return value is 0, contains malloced string + * param[in] yrestype Resolved Yang type + * param[in] type Original type + * @param[in] val Value to match + * @param[out] ysubp Sub-type of ys that matches val + * @retval -1 Error (fatal), with errno set to indicate error + * @retval 0 Validation not OK, malloced reason is returned. Free reason with free() + * @retval 1 Validation OK */ static int ys_cv_validate_union(clicon_handle h, yang_stmt *ys, char **reason, yang_stmt *yrestype, - char *type, /* orig type */ + char *type, char *val, yang_stmt **ysubp) {