From c53877eb78f1c657b0b280a7cc90479fcb752720 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sat, 29 Jun 2024 10:26:25 +0200 Subject: [PATCH] YANG namespace sanity check YANG shared fix for empty revisions --- lib/src/clixon_yang_module.c | 14 ++++++++++++++ lib/src/clixon_yang_schema_mount.c | 7 +++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/src/clixon_yang_module.c b/lib/src/clixon_yang_module.c index 8ca7643c..f42044a1 100644 --- a/lib/src/clixon_yang_module.c +++ b/lib/src/clixon_yang_module.c @@ -855,6 +855,8 @@ yang_lib2yspec(clixon_handle h, int retval = -1; cxobj *xi; char *name; + char *ns; + char *ns2; char *revision; cvec *nsc = NULL; cxobj **vec = NULL; @@ -870,6 +872,7 @@ yang_lib2yspec(clixon_handle h, xi = vec[i]; if ((name = xml_find_body(xi, "name")) == NULL) continue; + ns = xml_find_body(xi, "namespace"); revision = xml_find_body(xi, "revision"); if ((ymod = yang_find(yspec, Y_MODULE, name)) != NULL || (ymod = yang_find(yspec, Y_SUBMODULE, name)) != NULL){ @@ -887,6 +890,17 @@ yang_lib2yspec(clixon_handle h, } if (yang_parse_module(h, name, revision, yspec, NULL) == NULL) goto fail; + /* Sanity check: if given namespace differs from namespace in file */ + if (ns != NULL) { + if ((ymod = yang_find(yspec, Y_MODULE, name)) != NULL) { + if ((ns2 = yang_find_mynamespace(ymod)) != NULL){ + if (strcmp(ns, ns2) != 0){ + clixon_err(OE_YANG, 0, "Module:%s namespace mismatch %s vs %s", name, ns, ns2); + goto fail; + } + } + } + } } #ifdef YANG_SCHEMA_MOUNT_YANG_LIB_FORCE /* Force add ietf-yang-library@2019-01-04 on all mount-points diff --git a/lib/src/clixon_yang_schema_mount.c b/lib/src/clixon_yang_schema_mount.c index 8c96e897..ca4acf53 100644 --- a/lib/src/clixon_yang_schema_mount.c +++ b/lib/src/clixon_yang_schema_mount.c @@ -865,7 +865,7 @@ yang_schema_cmp_kludge(clixon_handle h, } } revision2 = xml_find_body(x2, "revision"); - if (clicon_strcmp(revision1, revision2) != 0){ + if (revision1 && revision2 && clicon_strcmp(revision1, revision2) != 0){ clixon_debug(CLIXON_DBG_YANG, "revision mismatch %s %s\n", revision1, revision2); goto noteq; } @@ -899,7 +899,7 @@ yang_schema_cmp_kludge(clixon_handle h, } } revision1 = xml_find_body(x1, "revision"); - if (clicon_strcmp(revision1, revision2) != 0){ + if (revision1 && revision2 && clicon_strcmp(revision1, revision2) != 0){ clixon_debug(CLIXON_DBG_YANG, "revision mismatch %s %s\n", revision1, revision2); goto noteq; } @@ -1037,11 +1037,14 @@ yang_schema_yanglib_parse_mount(clixon_handle h, /* Parse it and set mount-point */ if ((yspec = yspec_new()) == NULL) goto done; + clixon_debug(CLIXON_DBG_YANG, "new yang-spec: %p", yspec); if ((ret = yang_lib2yspec(h, xyanglib, yspec)) < 0) goto done; if (ret == 0) goto anydata; } + else + clixon_debug(CLIXON_DBG_YANG, "shared yang-spec: %p", yspec); if (xml_yang_mount_set(h, xt, yspec) < 0) goto done; if (shared)