Skip to content

Commit a97c363

Browse files
committed
patch 8.2.3006: crash when echoing a value very early
Problem: Crash when echoing a value very early. (Naruhiko Nishino) Solution: Do not use a NUL to truncate the message, make a copy. (closes #8388)
1 parent f57b43c commit a97c363

3 files changed

Lines changed: 27 additions & 9 deletions

File tree

src/message.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,19 +2751,21 @@ msg_puts_printf(char_u *str, int maxlen)
27512751

27522752
if (*p != NUL && !(silent_mode && p_verbose == 0))
27532753
{
2754-
int c = -1;
2754+
char_u *tofree = NULL;
27552755

27562756
if (maxlen > 0 && STRLEN(p) > (size_t)maxlen)
27572757
{
2758-
c = p[maxlen];
2759-
p[maxlen] = 0;
2758+
tofree = vim_strnsave(p, (size_t)maxlen);
2759+
p = tofree;
2760+
}
2761+
if (p != NULL)
2762+
{
2763+
if (info_message)
2764+
mch_msg((char *)p);
2765+
else
2766+
mch_errmsg((char *)p);
2767+
vim_free(tofree);
27602768
}
2761-
if (info_message)
2762-
mch_msg((char *)p);
2763-
else
2764-
mch_errmsg((char *)p);
2765-
if (c != -1)
2766-
p[maxlen] = c;
27672769
}
27682770

27692771
msg_didout = TRUE; // assume that line is not empty

src/testdir/test_startup.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,4 +1301,18 @@ func Test_write_in_vimrc()
13011301
call delete('Xvimrc')
13021302
endfunc
13031303

1304+
func Test_echo_true_in_cmd()
1305+
let lines =<< trim END
1306+
echo v:true
1307+
call writefile(['done'], 'Xresult')
1308+
END
1309+
call writefile(lines, 'Xscript')
1310+
if RunVim([], [], '--cmd "source Xscript" --c q')
1311+
call assert_equal(['done'], readfile('Xresult'))
1312+
endif
1313+
call delete('Xscript')
1314+
call delete('Xresult')
1315+
1316+
endfunc
1317+
13041318
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
3006,
753755
/**/
754756
3005,
755757
/**/

0 commit comments

Comments
 (0)