]> granicus.if.org Git - vim/commitdiff
patch 9.0.0164: using freed memory with put command v9.0.0164
authorBram Moolenaar <Bram@vim.org>
Sun, 7 Aug 2022 17:09:10 +0000 (18:09 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 7 Aug 2022 17:09:10 +0000 (18:09 +0100)
Problem:    Using freed memory with put command.
Solution:   Get byte offset before replacing the line.

src/register.c
src/version.c

index f34a0ddbb08a73632da18ce496737f166616659c..2dafeabf5ed3096f73dfb77be4fda1513b6e9f46 100644 (file)
@@ -2099,13 +2099,15 @@ do_put(
                        ptr += yanklen;
                    }
                    STRMOVE(ptr, oldp + col);
-                   ml_replace(lnum, newp, FALSE);
-
-                   inserted_bytes(lnum, col, totlen);
 
                    // compute the byte offset for the last character
                    first_byte_off = mb_head_off(newp, ptr - 1);
 
+                   // Note: this may free "newp"
+                   ml_replace(lnum, newp, FALSE);
+
+                   inserted_bytes(lnum, col, totlen);
+
                    // Place cursor on last putted char.
                    if (lnum == curwin->w_cursor.lnum)
                    {
index 9207b7f69fd320fcf42444463bcf8aea585a0c51..be59f1be2e8ade8b241e40aba605a4edb9d3938a 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    164,
 /**/
     163,
 /**/