From 2dadd00136062d1e232b31d2643795d00c5c3fd5 Mon Sep 17 00:00:00 2001 From: Mohil-Ahuja Date: Fri, 4 Dec 2026 14:46:15 +0530 Subject: [PATCH] schema compile BUGFIX quote in a log path value A special tag value in the log path, such as the target of an augment, is quoted with ' and removing it skips the quoted part. A ' inside the value, as in augment "/c'x", unbalanced the quotes so the backwards scan went past the start of the path and read out of bounds. Quote the value with " if it includes ', only end a quoted part with its own quote character, and never scan before the start of the path. --- src/schema_compile.c | 21 ++++++++++++------- .../utests/schema/test_tree_schema_compile.c | 6 ++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/schema_compile.c b/src/schema_compile.c index 492fe921e..9b9560dfd 100644 --- a/src/schema_compile.c +++ b/src/schema_compile.c @@ -62,11 +62,16 @@ lysc_update_path(struct lysc_ctx *ctx, const struct lys_module *parent_module, c if (ctx->path[ctx->path_used - 1] == '}') { do { --ctx->path_used; - if (ctx->path[ctx->path_used] == '\'') { - /* skip quoted string */ - quot = quot ? 0 : ctx->path[ctx->path_used]; + if ((ctx->path[ctx->path_used] == '\'') || (ctx->path[ctx->path_used] == '"')) { + /* skip quoted string, the other quote character may be a part of it */ + if (!quot) { + quot = ctx->path[ctx->path_used]; + } else if (quot == ctx->path[ctx->path_used]) { + quot = 0; + } } - } while (quot || ((ctx->path[ctx->path_used] != '=') && (ctx->path[ctx->path_used] != '{'))); + } while (ctx->path_used && (quot || ((ctx->path[ctx->path_used] != '=') && + (ctx->path[ctx->path_used] != '{')))); if (ctx->path[ctx->path_used] == '=') { ctx->path[ctx->path_used++] = '}'; } else { @@ -75,7 +80,7 @@ lysc_update_path(struct lysc_ctx *ctx, const struct lys_module *parent_module, c } } else { remove_nodelevel: - for ( ; ctx->path[ctx->path_used] != '/'; --ctx->path_used) {} + for ( ; ctx->path_used && (ctx->path[ctx->path_used] != '/'); --ctx->path_used) {} if (!ctx->path_used) { free(ctx->path); ctx->path = NULL; @@ -89,7 +94,7 @@ lysc_update_path(struct lysc_ctx *ctx, const struct lys_module *parent_module, c } } else { if (!parent_module && ctx->path_used && (ctx->path[ctx->path_used - 1] == '}') && - (ctx->path[ctx->path_used - 2] != '\'')) { + (ctx->path[ctx->path_used - 2] != '\'') && (ctx->path[ctx->path_used - 2] != '"')) { /* extension of the special tag */ spec = 1; --ctx->path_used; @@ -104,7 +109,9 @@ lysc_update_path(struct lysc_ctx *ctx, const struct lys_module *parent_module, c ly_append_str(&ctx->path, &ctx->path_size, &ctx->path_used, "/%s:%s", ctx->cur_mod->name, name); } } else { - ly_append_str(&ctx->path, &ctx->path_size, &ctx->path_used, "='%s'}", name); + /* use the quote character that is not in the value */ + quot = strchr(name, '\'') ? '"' : '\''; + ly_append_str(&ctx->path, &ctx->path_size, &ctx->path_used, "=%c%s%c}", quot, name, quot); } } diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c index 252f39cdd..927c23185 100644 --- a/tests/utests/schema/test_tree_schema_compile.c +++ b/tests/utests/schema/test_tree_schema_compile.c @@ -3121,6 +3121,12 @@ test_augment(void **state) "augment /x/ {leaf a {type int8;}}}", LYS_IN_YANG, &mod)); CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"/x/\" - unexpected end of expression.", "/aa:{augment='/x/'}", 0); + /* a quote in the target must not break removing the augment from the log path */ + assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aq {namespace urn:aq;prefix aq; container c {leaf a {type string;}}" + "augment \"/c'x\" {leaf a {type int8;}}}", LYS_IN_YANG, &mod)); + CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"/c'x\" - invalid syntax.", "/aq:{augment=\"/c'x\"}", 0); + CHECK_LOG_CTX("Unterminated string delimited with ' ('x).", "/aq:{augment=\"/c'x\"}", 0); + assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}" "augment /x {leaf a {type int8;}}}", LYS_IN_YANG, &mod)); CHECK_LOG_CTX("Augment target node \"/x\" from module \"aa\" was not found.", "/aa:{augment='/x'}", 0);