Skip to content

Commit e7bb3f9

Browse files
committed
libyang BUGFIX properly handle union values
Fixes #2342
1 parent 29e9db2 commit e7bb3f9

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/schema_compile.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ lys_compile_unres_dflt(struct lysc_ctx *ctx, struct lysc_node *node, struct lysc
937937
{
938938
LY_ERR ret;
939939
uint32_t options;
940+
struct lyd_value *val;
940941
struct ly_err_item *err = NULL;
941942

942943
options = (ctx->ctx->flags & LY_CTX_REF_IMPLEMENTED) ? LYPLG_TYPE_STORE_IMPLEMENT : 0;
@@ -963,11 +964,16 @@ lys_compile_unres_dflt(struct lysc_ctx *ctx, struct lysc_node *node, struct lysc
963964
}
964965

965966
LY_ATOMIC_INC_BARRIER(((struct lysc_type *)storage->realtype)->refcount);
966-
if (storage->realtype->basetype == LY_TYPE_INST) {
967+
if (storage->realtype->basetype == LY_TYPE_UNION) {
968+
val = &storage->subvalue->value;
969+
} else {
970+
val = storage;
971+
}
972+
if (val->realtype->basetype == LY_TYPE_INST) {
967973
/* ly_path includes references to other nodes, in case they are in foreign modules, the context would
968974
* need to be freed in specific order to avoid accessing freed memory, so just avoid storing it */
969-
ly_path_free(storage->target);
970-
storage->target = NULL;
975+
ly_path_free(val->target);
976+
val->target = NULL;
971977
}
972978
return LY_SUCCESS;
973979
}

src/xpath.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3690,6 +3690,7 @@ xpath_bit_is_set(struct lyxp_set **args, uint32_t UNUSED(arg_count), struct lyxp
36903690
struct lyd_node_term *leaf;
36913691
struct lysc_node_leaf *sleaf;
36923692
struct lyd_value_bits *bits;
3693+
struct lyd_value *val;
36933694
LY_ERR rc = LY_SUCCESS;
36943695
LY_ARRAY_COUNT_TYPE u;
36953696

@@ -3725,10 +3726,14 @@ xpath_bit_is_set(struct lyxp_set **args, uint32_t UNUSED(arg_count), struct lyxp
37253726
LY_CHECK_RET(rc);
37263727

37273728
set_fill_boolean(set, 0);
3728-
if (args[0]->used) {
3729+
if (args[0]->used && (args[0]->val.nodes[0].node->schema->nodetype & LYD_NODE_TERM)) {
37293730
leaf = (struct lyd_node_term *)args[0]->val.nodes[0].node;
3730-
if ((leaf->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST)) && (leaf->value.realtype->basetype == LY_TYPE_BITS)) {
3731-
LYD_VALUE_GET(&leaf->value, bits);
3731+
val = &leaf->value;
3732+
if (val->realtype->basetype == LY_TYPE_UNION) {
3733+
val = &val->subvalue->value;
3734+
}
3735+
if (val->realtype->basetype == LY_TYPE_BITS) {
3736+
LYD_VALUE_GET(val, bits);
37323737
LY_ARRAY_FOR(bits->items, u) {
37333738
if (!strcmp(bits->items[u]->name, args[1]->val.str)) {
37343739
set_fill_boolean(set, 1);
@@ -4200,17 +4205,21 @@ xpath_derived_(struct lyxp_set **args, struct lyxp_set *set, uint32_t options, l
42004205
leaf = (struct lyd_node_term *)args[0]->val.nodes[i].node;
42014206
sleaf = (struct lysc_node_leaf *)leaf->schema;
42024207
val = &leaf->value;
4203-
if (!sleaf || !(sleaf->nodetype & LYD_NODE_TERM) || (leaf->value.realtype->basetype != LY_TYPE_IDENT)) {
4208+
if (!sleaf || !(sleaf->nodetype & LYD_NODE_TERM)) {
42044209
/* uninteresting */
42054210
continue;
42064211
}
42074212
} else {
42084213
meta = args[0]->val.meta[i].meta;
42094214
val = &meta->value;
4210-
if (val->realtype->basetype != LY_TYPE_IDENT) {
4211-
/* uninteresting */
4212-
continue;
4213-
}
4215+
}
4216+
4217+
if (val->realtype->basetype == LY_TYPE_UNION) {
4218+
val = &val->subvalue->value;
4219+
}
4220+
if (val->realtype->basetype != LY_TYPE_IDENT) {
4221+
/* uninteresting */
4222+
continue;
42144223
}
42154224

42164225
/* check the identity itself */

0 commit comments

Comments
 (0)