Skip to content

Commit 8a01f96

Browse files
committed
patch 8.0.0085
Problem: Using freed memory with recursive function call. (Dominique Pelle) Solution: Make a copy of the function name.
1 parent 7618e00 commit 8a01f96

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

src/eval.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4339,10 +4339,17 @@ eval7(
43394339
* use its contents. */
43404340
s = deref_func_name(s, &len, &partial, !evaluate);
43414341

4342-
/* Invoke the function. */
4343-
ret = get_func_tv(s, len, rettv, arg,
4344-
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
4345-
&len, evaluate, partial, NULL);
4342+
/* Need to make a copy, in case evaluating the arguments makes
4343+
* the name invalid. */
4344+
s = vim_strsave(s);
4345+
if (s == NULL)
4346+
ret = FAIL;
4347+
else
4348+
/* Invoke the function. */
4349+
ret = get_func_tv(s, len, rettv, arg,
4350+
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
4351+
&len, evaluate, partial, NULL);
4352+
vim_free(s);
43464353

43474354
/* If evaluate is FALSE rettv->v_type was not set in
43484355
* get_func_tv, but it's needed in handle_subscript() to parse
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
"Tests for nested functions
22
"
3-
function! NestedFunc()
4-
fu! Func1()
3+
func NestedFunc()
4+
func! Func1()
55
let g:text .= 'Func1 '
6-
endfunction
6+
endfunc
77
call Func1()
8-
fu! s:func2()
8+
func! s:func2()
99
let g:text .= 's:func2 '
10-
endfunction
10+
endfunc
1111
call s:func2()
12-
fu! s:_func3()
12+
func! s:_func3()
1313
let g:text .= 's:_func3 '
14-
endfunction
14+
endfunc
1515
call s:_func3()
1616
let fn = 'Func4'
17-
fu! {fn}()
17+
func! {fn}()
1818
let g:text .= 'Func4 '
19-
endfunction
19+
endfunc
2020
call {fn}()
2121
let fn = 'func5'
22-
fu! s:{fn}()
22+
func! s:{fn}()
2323
let g:text .= 's:func5'
24-
endfunction
24+
endfunc
2525
call s:{fn}()
26-
endfunction
26+
endfunc
2727

28-
function! Test_nested_functions()
28+
func Test_nested_functions()
2929
let g:text = ''
3030
call NestedFunc()
3131
call assert_equal('Func1 s:func2 s:_func3 Func4 s:func5', g:text)
3232
endfunction
33+
34+
func Test_nested_argument()
35+
func g:X()
36+
let g:Y = function('sort')
37+
endfunc
38+
let g:Y = function('sort')
39+
echo g:Y([], g:X())
40+
delfunc g:X
41+
unlet g:Y
42+
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+
85,
767769
/**/
768770
84,
769771
/**/

0 commit comments

Comments
 (0)