Skip to content

Commit a701b3b

Browse files
committed
patch 8.0.0575: using freed memory when resetting 'indentexpr'
Problem: Using freed memory when resetting 'indentexpr' while evaluating it. (Dominique Pelle) Solution: Make a copy of 'indentexpr'.
1 parent 99895ea commit a701b3b

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/misc1.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9252,6 +9252,7 @@ find_match(int lookfor, linenr_T ourscope)
92529252
get_expr_indent(void)
92539253
{
92549254
int indent;
9255+
char_u *inde_copy;
92559256
pos_T save_pos;
92569257
colnr_T save_curswant;
92579258
int save_set_curswant;
@@ -9268,7 +9269,16 @@ get_expr_indent(void)
92689269
if (use_sandbox)
92699270
++sandbox;
92709271
++textlock;
9271-
indent = (int)eval_to_number(curbuf->b_p_inde);
9272+
9273+
/* Need to make a copy, the 'indentexpr' option could be changed while
9274+
* evaluating it. */
9275+
inde_copy = vim_strsave(curbuf->b_p_inde);
9276+
if (inde_copy != NULL)
9277+
{
9278+
indent = (int)eval_to_number(inde_copy);
9279+
vim_free(inde_copy);
9280+
}
9281+
92729282
if (use_sandbox)
92739283
--sandbox;
92749284
--textlock;

src/testdir/test_options.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,16 @@ func Test_set_values()
319319
throw 'Skipped: opt_test.vim does not exist'
320320
endif
321321
endfunc
322+
323+
func ResetIndentexpr()
324+
set indentexpr=
325+
endfunc
326+
327+
func Test_set_indentexpr()
328+
" this was causing usage of freed memory
329+
set indentexpr=ResetIndentexpr()
330+
new
331+
call feedkeys("i\<c-f>", 'x')
332+
call assert_equal('', &indentexpr)
333+
bwipe!
334+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
575,
767769
/**/
768770
574,
769771
/**/

0 commit comments

Comments
 (0)