context BUGFIX dereferencing NULL pointer when working with schema without revision
diff --git a/src/context.c b/src/context.c
index ff6dc84..4e1b0bc 100644
--- a/src/context.c
+++ b/src/context.c
@@ -367,7 +367,7 @@
* is supposed to be the oldest one */
newest = mod;
date_newest = NULL;
- } else {
+ } else if ((mod->compiled && mod->compiled->revs) || (!mod->compiled && mod->parsed->revs)) {
if (!date_newest) {
if (newest->compiled) {
date_newest = newest->compiled->revs[0].date;
diff --git a/tests/src/test_context.c b/tests/src/test_context.c
index 992fdfa..a5ad471 100644
--- a/tests/src/test_context.c
+++ b/tests/src/test_context.c
@@ -280,6 +280,7 @@
struct ly_ctx *ctx;
const struct lys_module *mod, *mod2;
+ const char *str0 = "module a {namespace urn:a;prefix a;}";
const char *str1 = "module a {namespace urn:a;prefix a;revision 2018-10-23;}";
const char *str2 = "module a {namespace urn:a;prefix a;revision 2018-10-23;revision 2018-10-24;}";
@@ -308,7 +309,7 @@
assert_non_null(ly_ctx_get_module(ctx, "ietf-yang-metadata", "2016-08-05"));
assert_non_null(ly_ctx_get_module(ctx, "ietf-yang-types", "2013-07-15"));
assert_non_null(ly_ctx_get_module(ctx, "ietf-inet-types", "2013-07-15"));
- assert_non_null(ly_ctx_get_module(ctx, "ietf-datastores", "2017-08-17"));
+ assert_non_null(ly_ctx_get_module_ns(ctx, "urn:ietf:params:xml:ns:yang:ietf-datastores", "2017-08-17"));
/* select module by revision */
mod = lys_parse_mem(ctx, str1, LYS_IN_YANG);
@@ -326,6 +327,11 @@
assert_ptr_equal(mod, mod2);
mod2 = ly_ctx_get_module_latest_ns(ctx, mod->parsed->ns);
assert_ptr_equal(mod, mod2);
+ /* work with module with no revision */
+ mod = lys_parse_mem_(ctx, str0, LYS_IN_YANG, NULL, 0);
+ assert_non_null(mod);
+ assert_ptr_equal(mod, ly_ctx_get_module(ctx, "a", NULL));
+ assert_ptr_not_equal(mod, ly_ctx_get_module_latest(ctx, "a"));
/* cleanup */
ly_ctx_destroy(ctx, NULL);