parser BUGFIX forbid empty patterns

Refs sysrepo/sysrepo#2572
diff --git a/src/parser_yang.c b/src/parser_yang.c
index d6481d4..beedbf1 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -585,6 +585,10 @@
                 (*flags) |= ctx->in->current[0] == '\'' ? LYS_SINGLEQUOTED : LYS_DOUBLEQUOTED;
             }
             LY_CHECK_GOTO(ret = read_qstring(ctx, arg, word_p, word_b, word_len, &buf_len), error);
+            if (!*word_p) {
+                /* do not return NULL word */
+                *word_p = "";
+            }
             goto str_end;
         case '/':
             if (ctx->in->current[1] == '/') {
@@ -2053,6 +2057,12 @@
     /* get value */
     LY_CHECK_RET(get_argument(ctx, Y_STR_ARG, NULL, &word, &buf, &word_len));
 
+    /* empty pattern is not valid */
+    if (!strlen(word)) {
+        LOGVAL_PARSER(ctx, LY_VCODE_INVAL, word_len, word, "pattern");
+        return LY_EVALID;
+    }
+
     /* add special meaning first byte */
     if (buf) {
         buf = ly_realloc(buf, word_len + 2);
diff --git a/src/parser_yin.c b/src/parser_yin.c
index 6ab6921..1dd2856 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -650,6 +650,13 @@
     LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &real_value, Y_STR_ARG, LY_STMT_PATTERN));
     size_t len = strlen(real_value);
 
+    /* empty pattern is not valid */
+    if (!len) {
+        LOGVAL_PARSER((struct lys_parser_ctx *)ctx, LY_VCODE_INVAL_YIN, real_value, "value", ly_stmt2str(LY_STMT_PATTERN));
+        lydict_remove(ctx->xmlctx->ctx, real_value);
+        return LY_EVALID;
+    }
+
     saved_value = malloc(len + 2);
     LY_CHECK_ERR_RET(!saved_value, LOGMEM(ctx->xmlctx->ctx), LY_EMEM);
     memmove(saved_value + 1, real_value, len);