Skip to content

Commit 7948136

Browse files
committed
patch 8.2.5169: nested :source may use NULL pointer
Problem: Nested :source may use NULL pointer. Solution: Do not use the NULL pointer.
1 parent fee511c commit 7948136

3 files changed

Lines changed: 46 additions & 19 deletions

File tree

src/eval.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,27 +2387,32 @@ eval0_retarg(
23872387

23882388
p = skipwhite(arg);
23892389
ret = eval1(&p, rettv, evalarg);
2390-
expr_end = p;
2391-
p = skipwhite(p);
23922390

2393-
// In Vim9 script a command block is not split at NL characters for
2394-
// commands using an expression argument. Skip over a '#' comment to check
2395-
// for a following NL. Require white space before the '#'.
2396-
if (in_vim9script() && p > expr_end && retarg == NULL)
2397-
while (*p == '#')
2398-
{
2399-
char_u *nl = vim_strchr(p, NL);
2391+
if (ret != FAIL)
2392+
{
2393+
expr_end = p;
2394+
p = skipwhite(p);
24002395

2401-
if (nl == NULL)
2402-
break;
2403-
p = skipwhite(nl + 1);
2404-
if (eap != NULL && *p != NUL)
2405-
eap->nextcmd = p;
2406-
check_for_end = FALSE;
2407-
}
2396+
// In Vim9 script a command block is not split at NL characters for
2397+
// commands using an expression argument. Skip over a '#' comment to
2398+
// check for a following NL. Require white space before the '#'.
2399+
if (in_vim9script() && p > expr_end && retarg == NULL)
2400+
while (*p == '#')
2401+
{
2402+
char_u *nl = vim_strchr(p, NL);
2403+
2404+
if (nl == NULL)
2405+
break;
2406+
p = skipwhite(nl + 1);
2407+
if (eap != NULL && *p != NUL)
2408+
eap->nextcmd = p;
2409+
check_for_end = FALSE;
2410+
}
2411+
2412+
if (check_for_end)
2413+
end_error = !ends_excmd2(arg, p);
2414+
}
24082415

2409-
if (ret != FAIL && check_for_end)
2410-
end_error = !ends_excmd2(arg, p);
24112416
if (ret == FAIL || end_error)
24122417
{
24132418
if (ret != FAIL)
@@ -2433,7 +2438,8 @@ eval0_retarg(
24332438
// Some of the expression may not have been consumed. Do not check for
24342439
// a next command to avoid more errors, unless "|" is following, which
24352440
// could only be a command separator.
2436-
if (eap != NULL && skipwhite(p)[0] == '|' && skipwhite(p)[1] != '|')
2441+
if (eap != NULL && p != NULL
2442+
&& skipwhite(p)[0] == '|' && skipwhite(p)[1] != '|')
24372443
eap->nextcmd = check_nextcmd(p);
24382444
return FAIL;
24392445
}

src/testdir/test_vimscript.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7528,6 +7528,25 @@ func Test_for_over_string()
75287528
call assert_equal('', res)
75297529
endfunc
75307530

7531+
" Test for deeply nested :source command {{{1
7532+
func Test_deeply_nested_source()
7533+
let lines =<< trim END
7534+
7535+
so
7536+
sil 0scr
7537+
delete
7538+
so
7539+
0
7540+
END
7541+
call writefile(["vim9 silent! @0 \n/"] + lines, 'Xnested.vim')
7542+
7543+
" this must not crash
7544+
let cmd = GetVimCommand() .. " -e -s -S Xnested.vim -c qa!"
7545+
call system(cmd)
7546+
7547+
call delete('Xnested.vim')
7548+
endfunc
7549+
75317550
"-------------------------------------------------------------------------------
75327551
" Modelines {{{1
75337552
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/version.c

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

736736
static int included_patches[] =
737737
{ /* Add new patch number below this line */
738+
/**/
739+
5169,
738740
/**/
739741
5168,
740742
/**/

0 commit comments

Comments
 (0)