YANG parser BUGFIX check for empty statement argument where identifier expected
Fixes #791
diff --git a/src/parser_yang.c b/src/parser_yang.c
index 5d94c13..bf1361c 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -564,6 +564,11 @@
}
string_end:
+ if (arg <= Y_PREF_IDENTIF_ARG && !(*word_len)) {
+ /* empty identifier */
+ LOGVAL_YANG(ctx, LYVE_SYNTAX_YANG, "Statement argument is required.");
+ return LY_EVALID;
+ }
return LY_SUCCESS;
}
diff --git a/tests/src/test_parser_yang.c b/tests/src/test_parser_yang.c
index 28fbac8..15dcd8c 100644
--- a/tests/src/test_parser_yang.c
+++ b/tests/src/test_parser_yang.c
@@ -280,6 +280,14 @@
assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
logbuf_assert("Invalid character sequence \"}\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
+ str = "\"\";"; /* empty identifier is not allowed */
+ assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_IDENTIF_ARG, NULL, &word, &buf, &len));
+ logbuf_assert("Statement argument is required. Line number 1.");
+ logbuf_clean();
+ str = "\"\";"; /* empty reference identifier is not allowed */
+ assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
+ logbuf_assert("Statement argument is required. Line number 1.");
+
str = "hello/x\t"; /* slash is not an invalid character */
assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
assert_int_equal(7, len);