]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1531: crash when register contents ends up being invalid v9.0.1531
authorBram Moolenaar <Bram@vim.org>
Tue, 9 May 2023 16:09:30 +0000 (17:09 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 9 May 2023 16:09:30 +0000 (17:09 +0100)
Problem:    Crash when register contents ends up being invalid.
Solution:   Check "y_array" is not NULL.

src/register.c
src/testdir/test_registers.vim
src/version.c

index f3df79cfd6426546926b7187c2eb8053eff8e9ac..e481d843c249eec9679b572016a1d4168c167153 100644 (file)
@@ -301,7 +301,7 @@ get_register(
     if (copy)
     {
        // If we run out of memory some or all of the lines are empty.
-       if (reg->y_size == 0)
+       if (reg->y_size == 0 || y_current->y_array == NULL)
            reg->y_array = NULL;
        else
            reg->y_array = ALLOC_MULT(char_u *, reg->y_size);
index e966932478d8046ab3f24cc48696f0ef23178542..33ea0f4bd3e6c889965aab5d6b963fc43d5861f5 100644 (file)
@@ -835,6 +835,23 @@ func Test_end_reg_executing()
   bwipe!
 endfunc
 
+" This was causing a crash because y_append was ending up being NULL
+func Test_zero_y_append()
+  " Run in a separate Vim instance because changing 'encoding' may cause
+  " trouble for later tests.
+  let lines =<< trim END
+      d
+      silent ?n
+      next <sfile>
+      so
+      sil! norm 0V\80PS\ 3\11P
+      set enc=latin1
+       
+  END
+  call writefile(lines, 'XTest_zero_y_append', 'D')
+  call RunVim([], [], '-u NONE -i NONE -e -s -S XTest_zero_y_append -c qa\!')
+endfunc
+
 " Make sure that y_append is correctly reset
 " and the previous register is working as expected
 func Test_register_y_append_reset()
index 310803cb82938f69bba0f21803500b9f96525706..7ee9f575f9bd90f04e8e3cfcac404a45fd8b5988 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1531,
 /**/
     1530,
 /**/