Skip to content

Commit a371745

Browse files
committed
parsing BUGFIX invalid backward extension parent pointer
This patch fixes the issue if extensions are used within subsequent enum statements or within subsequent type statements of union type
1 parent cdad270 commit a371745

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/parser_yang.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,9 +1937,17 @@ parse_type_enum(struct lysp_yang_ctx *ctx, enum ly_stmt enum_kw, struct lysp_typ
19371937
size_t word_len;
19381938
enum ly_stmt kw;
19391939
struct lysp_type_enum *enm;
1940+
LY_ARRAY_COUNT_TYPE u, v;
19401941

19411942
LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *enums, enm, LY_EMEM);
19421943

1944+
/* revalidate the backward parent pointers from extensions */
1945+
LY_ARRAY_FOR(*enums, u) {
1946+
LY_ARRAY_FOR((*enums)[u].exts, v) {
1947+
(*enums)[u].exts[v].parent = &(*enums)[u];
1948+
}
1949+
}
1950+
19431951
/* get value */
19441952
LY_CHECK_RET(get_argument(ctx, enum_kw == LY_STMT_ENUM ? Y_STR_ARG : Y_IDENTIF_ARG, NULL, &word, &buf, &word_len));
19451953
if (enum_kw == LY_STMT_ENUM) {
@@ -2246,6 +2254,7 @@ parse_type(struct lysp_yang_ctx *ctx, struct lysp_type *type)
22462254
size_t word_len;
22472255
enum ly_stmt kw;
22482256
struct lysp_type *nest_type;
2257+
LY_ARRAY_COUNT_TYPE u, v;
22492258

22502259
if (type->name) {
22512260
LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "type");
@@ -2329,6 +2338,12 @@ parse_type(struct lysp_yang_ctx *ctx, struct lysp_type *type)
23292338
break;
23302339
case LY_STMT_TYPE:
23312340
LY_ARRAY_NEW_RET(PARSER_CTX(ctx), type->types, nest_type, LY_EMEM);
2341+
/* revalidate the backward parent pointers from extensions */
2342+
LY_ARRAY_FOR(type->types, u) {
2343+
LY_ARRAY_FOR((type->types)[u].exts, v) {
2344+
(type->types)[u].exts[v].parent = &(type->types)[u];
2345+
}
2346+
}
23322347
LY_CHECK_RET(parse_type(ctx, nest_type));
23332348
type->flags |= LYS_SET_TYPE;
23342349
break;

tests/utests/basic/test_plugins.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ const char *simple = "module libyang-plugins-simple {"
3131
" type s:note {length 255;}"
3232
" s:hint \"some hint here\";"
3333
" }"
34+
" leaf enum1 {"
35+
" type enumeration {"
36+
" enum val1 {s:rt;}"
37+
" enum val2 {s:rt;}"
38+
" }"
39+
" }"
40+
" leaf u1 {"
41+
" type union {"
42+
" type string {s:rt;}"
43+
" type int8 {s:rt;}"
44+
" }"
45+
" }"
3446
" grouping grp1 {"
3547
" list l1 {key v; leaf v {type string;} leaf k {type string;}}"
3648
" list l2 {key v; leaf v {type string;} leaf k {type string;}}"
@@ -132,6 +144,8 @@ parse_clb2(struct lysp_ctx *UNUSED(pctx), struct lysp_ext_instance *ext)
132144
{
133145
struct lysp_refine *refine;
134146
struct lysp_tpdf *tpdf;
147+
struct lysp_type_enum *en;
148+
struct lysp_type *type;
135149
LY_ARRAY_COUNT_TYPE count = 0;
136150

137151
if (ext->parent_stmt == LY_STMT_REFINE) {
@@ -140,6 +154,12 @@ parse_clb2(struct lysp_ctx *UNUSED(pctx), struct lysp_ext_instance *ext)
140154
} else if (ext->parent_stmt == LY_STMT_TYPEDEF) {
141155
tpdf = (struct lysp_tpdf *)ext->parent;
142156
count = LY_ARRAY_COUNT(tpdf->exts);
157+
} else if (ext->parent_stmt == LY_STMT_ENUM) {
158+
en = (struct lysp_type_enum *)ext->parent;
159+
count = LY_ARRAY_COUNT(en->exts);
160+
} else if (ext->parent_stmt == LY_STMT_TYPE) {
161+
type = (struct lysp_type *)ext->parent;
162+
count = LY_ARRAY_COUNT(type->exts);
143163
} else {
144164
return LY_SUCCESS;
145165
}

0 commit comments

Comments
 (0)