]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1510: Search completion may use invalid memory v9.1.1510
authorzeertzjq <zeertzjq@outlook.com>
Sat, 5 Jul 2025 13:37:17 +0000 (15:37 +0200)
committerChristian Brabandt <cb@256bit.org>
Sat, 5 Jul 2025 13:37:17 +0000 (15:37 +0200)
Problem:  Search completion may use invalid memory (after 9.1.1490).
Solution: Don't get two line pointers at the same time (zeertzjq).

closes: #17661

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/cmdexpand.c
src/testdir/test_cmdline.vim
src/version.c

index b1c9ed67ab7f3c9fb99d1f74411df82d051481ed..5fa631c22acdd69dd583f9315a950f6505b4c229 100644 (file)
@@ -4638,14 +4638,11 @@ copy_substring_from_pos(pos_T *start, pos_T *end, char_u **match,
            || (start->lnum == end->lnum && start->col >= end->col))
        return FAIL; // invalid range
 
-    // Get line pointers
-    start_line = ml_get(start->lnum);
-    end_line = ml_get(end->lnum);
-
     // Use a growable string (ga)
     ga_init2(&ga, 1, 128);
 
     // Append start line from start->col to end
+    start_line = ml_get(start->lnum);
     char_u  *start_ptr = start_line + start->col;
     int            is_single_line = start->lnum == end->lnum;
 
@@ -4672,6 +4669,7 @@ copy_substring_from_pos(pos_T *start, pos_T *end, char_u **match,
     }
 
     // Append partial end line (up to word end)
+    end_line = ml_get(end->lnum);
     word_end = find_word_end(end_line + end->col);
     segment_len = (int)(word_end - end_line);
     if (ga_grow(&ga, segment_len) != OK)
index 844f58945c8da0ad749604f14ab5313253bfe959..f9533fa02914b0159f11fda670a658c93141ab98 100644 (file)
@@ -4504,6 +4504,7 @@ func Test_search_wildmenu_screendump()
   CheckScreendump
 
   let lines =<< trim [SCRIPT]
+    call test_override('alloc_lines', 1)
     set wildmenu wildcharm=<f5>
     call setline(1, ['the', 'these', 'the', 'foobar', 'thethe', 'thethere'])
   [SCRIPT]
index 3f0b6610ce2f2a5982111599a85d668f7d3858b7..4175c62e851bf0c13ef0d9e46d1ec1003f0f4f40 100644 (file)
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1510,
 /**/
     1509,
 /**/