From fa077839f0a895d8b4a360503fdb20399729dfbf Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 19 Apr 2022 09:24:40 +0200 Subject: [PATCH] Misc sanity checks and documentation --- apps/cli/cli_common.c | 2 +- lib/src/clixon_file.c | 6 ++++++ lib/src/clixon_yang_parse_lib.c | 4 ++-- test/lib.sh | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index 3e327cdf..41370189 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -862,7 +862,7 @@ load_config_file(clicon_handle h, } /* Open and parse local file into xml */ if ((fp = fopen(filename, "r")) == NULL){ - clicon_err(OE_UNIX, errno, "open(%s)", filename); + clicon_err(OE_UNIX, errno, "fopen(%s)", filename); goto done; } switch (format){ diff --git a/lib/src/clixon_file.c b/lib/src/clixon_file.c index 2a0b7199..aecc9d77 100644 --- a/lib/src/clixon_file.c +++ b/lib/src/clixon_file.c @@ -89,6 +89,10 @@ clicon_files_recursive1(const char *dir, int res = 0; struct stat st; + if (dir == NULL){ + clicon_err(OE_UNIX, EINVAL, "Requires dir != NULL"); + goto done; + } if ((dirp = opendir(dir)) != NULL) while ((dent = readdir(dirp)) != NULL) { if (dent->d_type == DT_DIR) { @@ -128,6 +132,8 @@ clicon_files_recursive1(const char *dir, return retval; } +/*! Find files recursively according to a regexp + */ int clicon_files_recursive(const char *dir, const char *regexp, diff --git a/lib/src/clixon_yang_parse_lib.c b/lib/src/clixon_yang_parse_lib.c index 432ff96f..4487e706 100644 --- a/lib/src/clixon_yang_parse_lib.c +++ b/lib/src/clixon_yang_parse_lib.c @@ -957,8 +957,8 @@ yang_parse_find_match(clicon_handle h, if (dp) free(dp); } - else if (strcmp(xml_name(xc), "CLICON_YANG_DIR") == 0){ - dir = xml_body(xc); + else if (strcmp(xml_name(xc), "CLICON_YANG_DIR") == 0 && + (dir = xml_body(xc)) != NULL){ /* get all matching files in this directory recursively */ if ((cvv = cvec_new(0)) == NULL){ clicon_err(OE_UNIX, errno, "cvec_new"); diff --git a/test/lib.sh b/test/lib.sh index 9e0034a8..0b534a83 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -218,7 +218,7 @@ if [ ! -d $dir ]; then mkdir $dir fi -# Default restconf configuration: http IPv4 +# Default restconf configuration: IPv4 # Can be placed in clixon-config # Note that https clause assumes there exists certs and keys in /etc/ssl,... # Args: