Skip to content

Commit 7ac5023

Browse files
committed
patch 9.0.1392: using NULL pointer with nested :open command
Problem: Using NULL pointer with nested :open command. Solution: Check that ccline.cmdbuff is not NULL.
1 parent 960dcbd commit 7ac5023

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/getchar.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,7 +3107,7 @@ check_end_reg_executing(int advance)
31073107
static int
31083108
vgetorpeek(int advance)
31093109
{
3110-
int c, c1;
3110+
int c;
31113111
int timedout = FALSE; // waited for more than 'timeoutlen'
31123112
// for mapping to complete or
31133113
// 'ttimeoutlen' for complete key code
@@ -3474,7 +3474,7 @@ vgetorpeek(int advance)
34743474
* to the user with showcmd.
34753475
*/
34763476
showcmd_idx = 0;
3477-
c1 = 0;
3477+
int showing_partial = FALSE;
34783478
if (typebuf.tb_len > 0 && advance && !exmode_active)
34793479
{
34803480
if (((State & (MODE_NORMAL | MODE_INSERT))
@@ -3489,7 +3489,7 @@ vgetorpeek(int advance)
34893489
edit_putchar(typebuf.tb_buf[typebuf.tb_off
34903490
+ typebuf.tb_len - 1], FALSE);
34913491
setcursor(); // put cursor back where it belongs
3492-
c1 = 1;
3492+
showing_partial = TRUE;
34933493
}
34943494
// need to use the col and row from above here
34953495
old_wcol = curwin->w_wcol;
@@ -3506,8 +3506,10 @@ vgetorpeek(int advance)
35063506
curwin->w_wrow = old_wrow;
35073507
}
35083508

3509-
// this looks nice when typing a dead character map
3509+
// This looks nice when typing a dead character map.
3510+
// There is no actual command line for get_number().
35103511
if ((State & MODE_CMDLINE)
3512+
&& get_cmdline_info()->cmdbuff != NULL
35113513
#if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
35123514
&& cmdline_star == 0
35133515
#endif
@@ -3516,7 +3518,7 @@ vgetorpeek(int advance)
35163518
{
35173519
putcmdline(typebuf.tb_buf[typebuf.tb_off
35183520
+ typebuf.tb_len - 1], FALSE);
3519-
c1 = 1;
3521+
showing_partial = TRUE;
35203522
}
35213523
}
35223524

@@ -3550,11 +3552,12 @@ vgetorpeek(int advance)
35503552

35513553
if (showcmd_idx != 0)
35523554
pop_showcmd();
3553-
if (c1 == 1)
3555+
if (showing_partial)
35543556
{
35553557
if (State & MODE_INSERT)
35563558
edit_unputchar();
3557-
if (State & MODE_CMDLINE)
3559+
if ((State & MODE_CMDLINE)
3560+
&& get_cmdline_info()->cmdbuff != NULL)
35583561
unputcmdline();
35593562
else
35603563
setcursor(); // put cursor back where it belongs

src/testdir/term_util.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ endfunc
5555
" "cols" - width of the terminal window (max. 78)
5656
" "statusoff" - number of lines the status is offset from default
5757
" "wait_for_ruler" - if zero then don't wait for ruler to show
58+
" "no_clean" - if non-zero then remove "--clean" from the command
5859
func RunVimInTerminal(arguments, options)
5960
" If Vim doesn't exit a swap file remains, causing other tests to fail.
6061
" Remove it here.
@@ -91,6 +92,10 @@ func RunVimInTerminal(arguments, options)
9192

9293
let cmd = GetVimCommandCleanTerm() .. reset_u7 .. a:arguments
9394

95+
if get(a:options, 'no_clean', 0)
96+
let cmd = substitute(cmd, '--clean', '', '')
97+
endif
98+
9499
let options = #{curwin: 1}
95100
if &termwinsize == ''
96101
let options.term_rows = rows

src/testdir/test_ex_mode.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,28 @@ func Test_open_command_flush_line()
134134
bwipe!
135135
endfunc
136136

137+
" FIXME: this doesn't fail without the fix but hangs
138+
func Skip_Test_open_command_state()
139+
" Tricky script that failed because State was not set properly
140+
let lines =<< trim END
141+
!ls ƒ
142+
0scìi
143+
so! Xsourced
144+
set t_û0=0
145+
v/-/o
146+
END
147+
call writefile(lines, 'XopenScript', '')
148+
149+
let sourced = ["!f\u0083\x02\<Esc>z=0"]
150+
call writefile(sourced, 'Xsourced', 'b')
151+
152+
CheckRunVimInTerminal
153+
let buf = RunVimInTerminal('-u NONE -i NONE -n -m -X -Z -e -s -S XopenScript -c qa!', #{rows: 6, wait_for_ruler: 0, no_clean: 1})
154+
sleep 3
155+
156+
call StopVimInTerminal(buf)
157+
endfunc
158+
137159
" Test for :g/pat/visual to run vi commands in Ex mode
138160
" This used to hang Vim before 8.2.0274.
139161
func Test_Ex_global()

src/version.c

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

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1392,
698700
/**/
699701
1391,
700702
/**/

0 commit comments

Comments
 (0)