Skip to content

Commit cae9c43

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

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/parser_yang.c

Lines changed: 8 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) {

tests/utests/basic/test_plugins.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ 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+
" }"
3440
" grouping grp1 {"
3541
" list l1 {key v; leaf v {type string;} leaf k {type string;}}"
3642
" list l2 {key v; leaf v {type string;} leaf k {type string;}}"
@@ -132,6 +138,7 @@ parse_clb2(struct lysp_ctx *UNUSED(pctx), struct lysp_ext_instance *ext)
132138
{
133139
struct lysp_refine *refine;
134140
struct lysp_tpdf *tpdf;
141+
struct lysp_type_enum *en;
135142
LY_ARRAY_COUNT_TYPE count = 0;
136143

137144
if (ext->parent_stmt == LY_STMT_REFINE) {
@@ -140,6 +147,9 @@ parse_clb2(struct lysp_ctx *UNUSED(pctx), struct lysp_ext_instance *ext)
140147
} else if (ext->parent_stmt == LY_STMT_TYPEDEF) {
141148
tpdf = (struct lysp_tpdf *)ext->parent;
142149
count = LY_ARRAY_COUNT(tpdf->exts);
150+
} else if (ext->parent_stmt == LY_STMT_ENUM) {
151+
en = (struct lysp_type_enum *)ext->parent;
152+
count = LY_ARRAY_COUNT(en->exts);
143153
} else {
144154
return LY_SUCCESS;
145155
}

0 commit comments

Comments
 (0)