lyb BUGFIX null pointer dereference
diff --git a/src/parser_lyb.c b/src/parser_lyb.c
index de8e6ae..e88cfe3 100644
--- a/src/parser_lyb.c
+++ b/src/parser_lyb.c
@@ -746,7 +746,7 @@
int r, ret = 0;
uint8_t i, count = 0;
const struct lys_module *mod;
- struct lys_type *type;
+ struct lys_type **type;
struct lyd_attr *attr = NULL;
struct lys_ext_instance_complex *ext;
struct ly_ctx *ctx = node->schema->module->ctx;
@@ -801,10 +801,13 @@
attr->name = lydict_insert(ctx, attr->annotation->arg_value, 0);
/* get the type */
- type = *(struct lys_type **)lys_ext_complex_get_substmt(LY_STMT_TYPE, attr->annotation, NULL);
+ type = (struct lys_type **)lys_ext_complex_get_substmt(LY_STMT_TYPE, attr->annotation, NULL);
+ if (!type || !(*type)) {
+ goto error;
+ }
/* attribute value */
- ret += (r = lyb_parse_value(type, NULL, attr, data, unres, lybs));
+ ret += (r = lyb_parse_value(*type, NULL, attr, data, unres, lybs));
LYB_HAVE_READ_GOTO(r, data, error);
stop_subtree:
diff --git a/src/printer_lyb.c b/src/printer_lyb.c
index ea6fe3a..a4d9b87 100644
--- a/src/printer_lyb.c
+++ b/src/printer_lyb.c
@@ -838,7 +838,7 @@
int r, ret = 0;
uint8_t count;
struct lyd_attr *iter;
- struct lys_type *type;
+ struct lys_type **type;
/* count attributes */
for (count = 0, iter = attr; iter; ++count, iter = iter->next) {
@@ -875,13 +875,13 @@
}
/* get the type */
- type = *(struct lys_type **)lys_ext_complex_get_substmt(LY_STMT_TYPE, attr->annotation, NULL);
- if (!type) {
+ type = (struct lys_type **)lys_ext_complex_get_substmt(LY_STMT_TYPE, attr->annotation, NULL);
+ if (!type || !(*type)) {
return -1;
}
/* attribute value */
- ret += (r = lyb_print_value(type, attr->value_str, attr->value, attr->value_type, attr->value_flags, 0, out, lybs));
+ ret += (r = lyb_print_value(*type, attr->value_str, attr->value, attr->value_type, attr->value_flags, 0, out, lybs));
if (r < 0) {
return -1;
}