Skip to content

Commit

Permalink
parser yang BUGFIX comments not allowed in unquoted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed Jul 30, 2024
1 parent 61a98ff commit 8ee7139
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 17 additions & 4 deletions src/parser_yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ get_argument(struct lysp_yang_ctx *ctx, enum yang_arg arg, uint16_t *flags, char
size_t buf_len = 0;
uint8_t prefix = 0;
ly_bool str_end = 0;
int comment;

/* word buffer - dynamically allocated */
*word_b = NULL;
Expand Down Expand Up @@ -627,18 +628,30 @@ get_argument(struct lysp_yang_ctx *ctx, enum yang_arg arg, uint16_t *flags, char
str_end = 1;
break;
case '/':
comment = 0;
if (ctx->in->current[1] == '/') {
/* one-line comment */
MOVE_INPUT(ctx, 2);
LY_CHECK_GOTO(ret = skip_comment(ctx, 1), error);
comment = 1;
} else if (ctx->in->current[1] == '*') {
/* block comment */
MOVE_INPUT(ctx, 2);
LY_CHECK_GOTO(ret = skip_comment(ctx, 2), error);
comment = 2;
} else {
/* not a comment after all */
LY_CHECK_GOTO(ret = buf_store_char(ctx, arg, word_p, word_len, word_b, &buf_len, 0, &prefix), error);
}

if (comment) {
if (*word_len) {
/* invalid comment sequence (RFC 7950 sec. 6.1.3.) */
LOGVAL_PARSER(ctx, LYVE_SYNTAX, "Invalid comment sequence \"%.2s\" in an unquoted string.", ctx->in->current);
ret = LY_EVALID;
goto error;
}

/* skip the comment */
MOVE_INPUT(ctx, 2);
LY_CHECK_GOTO(ret = skip_comment(ctx, comment), error);
}
break;
case ' ':
if (*word_len) {
Expand Down
2 changes: 0 additions & 2 deletions tests/utests/schema/test_yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ test_arg(void **state)

TEST_GET_ARGUMENT_SUCCESS("hello ", YCTX, Y_STR_ARG, "hello ", 5, " ", 1);

TEST_GET_ARGUMENT_SUCCESS("hello/*comment*/\n", YCTX, Y_STR_ARG, "hello/*comment*/\n", 5, "\n", 1);

TEST_GET_ARGUMENT_SUCCESS("\"hello\\n\\t\\\"\\\\\";", YCTX, Y_STR_ARG, "hello\n\t\"\\", 9, ";", 1);
free(buf);

Expand Down

0 comments on commit 8ee7139

Please sign in to comment.