]> granicus.if.org Git - vim/commitdiff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker v8.2.1755
authorBram Moolenaar <Bram@vim.org>
Sun, 27 Sep 2020 12:22:48 +0000 (14:22 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 27 Sep 2020 12:22:48 +0000 (14:22 +0200)
Problem:    Vim9: crash when using invalid heredoc marker. (Dhiraj Mishra)
Solution:   Check for NULL list. (closes #7027)  Fix comment character.

src/evalvars.c
src/testdir/test_vim9_assign.vim
src/version.c
src/vim9compile.c

index 3571169370c8f389a0687dc4985ac698d99cbaf9..9aa6d6554a6f621fe113520240dee73e9ffd5933 100644 (file)
@@ -558,6 +558,7 @@ heredoc_get(exarg_T *eap, char_u *cmd, int script_get)
     int                text_indent_len = 0;
     char_u     *text_indent = NULL;
     char_u     dot[] = ".";
+    int                comment_char = in_vim9script() ? '#' : '"';
 
     if (eap->getline == NULL)
     {
@@ -585,11 +586,11 @@ heredoc_get(exarg_T *eap, char_u *cmd, int script_get)
     }
 
     // The marker is the next word.
-    if (*cmd != NUL && *cmd != '"')
+    if (*cmd != NUL && *cmd != comment_char)
     {
        marker = skipwhite(cmd);
        p = skiptowhite(marker);
-       if (*skipwhite(p) != NUL && *skipwhite(p) != '"')
+       if (*skipwhite(p) != NUL && *skipwhite(p) != comment_char)
        {
            semsg(_(e_trailing_arg), p);
            return NULL;
index 94861e549ce234f9cd34bd4fc95b245e1dc40264..0a947346a09b84fdafeb735316a76026c83c9644 100644 (file)
@@ -732,4 +732,14 @@ def Test_assign_lambda()
   CheckScriptSuccess(lines)
 enddef
 
+def Test_heredoc()
+  var lines =<< trim END # comment
+    text
+  END
+  assert_equal(['text'], lines)
+
+  CheckDefFailure(['var lines =<< trim END X', 'END'], 'E488:')
+  CheckDefFailure(['var lines =<< trim END " comment', 'END'], 'E488:')
+enddef
+
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index 1ee6801c9e0e81da0b0a7ad4fbc89ce616bce192..2072b352903117c2023fa7a4de949689c286e2e7 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1755,
 /**/
     1754,
 /**/
index 2d640155fd9f84b330f6e2081d119348239a3bf5..832d7d93e1574765f60a3e4595a43973271af1ca 100644 (file)
@@ -4632,6 +4632,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
        eap->getline = exarg_getline;
        eap->cookie = cctx;
        l = heredoc_get(eap, op + 3, FALSE);
+       if (l == NULL)
+           return NULL;
 
        if (cctx->ctx_skip != SKIP_YES)
        {