Skip to content

Commit ac74d5e

Browse files
committed
patch 7.4.1616
Problem: Malformed channel request causes a hang. Solution: Drop malformed message. (Damien)
1 parent 829c8e3 commit ac74d5e

4 files changed

Lines changed: 34 additions & 10 deletions

File tree

src/channel.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,9 +1481,17 @@ channel_parse_json(channel_T *channel, int part)
14811481
* TODO: insert in front */
14821482
if (reader.js_buf[reader.js_used] != NUL)
14831483
{
1484-
channel_save(channel, part, reader.js_buf + reader.js_used,
1485-
(int)(reader.js_end - reader.js_buf) - reader.js_used);
1486-
ret = TRUE;
1484+
if (ret == FAIL)
1485+
{
1486+
ch_error(channel, "Decoding failed - discarding input");
1487+
ret = FALSE;
1488+
}
1489+
else
1490+
{
1491+
channel_save(channel, part, reader.js_buf + reader.js_used,
1492+
(int)(reader.js_end - reader.js_buf) - reader.js_used);
1493+
ret = TRUE;
1494+
}
14871495
}
14881496
else
14891497
ret = FALSE;
@@ -1586,12 +1594,14 @@ channel_exe_cmd(channel_T *channel, int part, typval_T *argv)
15861594

15871595
if (STRCMP(cmd, "ex") == 0)
15881596
{
1597+
ch_logs(channel, "Executing ex command '%s'", (char *)arg);
15891598
do_cmdline_cmd(arg);
15901599
}
15911600
else if (STRCMP(cmd, "normal") == 0)
15921601
{
15931602
exarg_T ea;
15941603

1604+
ch_logs(channel, "Executing normal command '%s'", (char *)arg);
15951605
ea.arg = arg;
15961606
ea.addr_count = 0;
15971607
ea.forceit = TRUE; /* no mapping */
@@ -1601,6 +1611,7 @@ channel_exe_cmd(channel_T *channel, int part, typval_T *argv)
16011611
{
16021612
exarg_T ea;
16031613

1614+
ch_log(channel, "redraw");
16041615
ea.forceit = *arg != NUL;
16051616
ex_redraw(&ea);
16061617
showruler(FALSE);
@@ -1642,11 +1653,18 @@ channel_exe_cmd(channel_T *channel, int part, typval_T *argv)
16421653
/* Don't pollute the display with errors. */
16431654
++emsg_skip;
16441655
if (!is_call)
1656+
{
1657+
ch_logs(channel, "Evaluating expression '%s'", (char *)arg);
16451658
tv = eval_expr(arg, NULL);
1646-
else if (func_call(arg, &argv[2], NULL, NULL, &res_tv) == OK)
1647-
tv = &res_tv;
1659+
}
16481660
else
1649-
tv = NULL;
1661+
{
1662+
ch_logs(channel, "Calling '%s'", (char *)arg);
1663+
if (func_call(arg, &argv[2], NULL, NULL, &res_tv) == OK)
1664+
tv = &res_tv;
1665+
else
1666+
tv = NULL;
1667+
}
16501668

16511669
if (argv[id_idx].v_type == VAR_NUMBER)
16521670
{
@@ -1848,10 +1866,7 @@ may_invoke_callback(channel_T *channel, int part)
18481866

18491867
if (argv[0].v_type == VAR_STRING)
18501868
{
1851-
char_u *cmd = argv[0].vval.v_string;
1852-
18531869
/* ["cmd", arg] or ["cmd", arg, arg] or ["cmd", arg, arg, arg] */
1854-
ch_logs(channel, "Executing %s command", (char *)cmd);
18551870
channel_exe_cmd(channel, part, argv);
18561871
free_tv(listtv);
18571872
return TRUE;

src/testdir/test_channel.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ def handle(self):
104104
print("sending: {}".format(cmd))
105105
self.request.sendall(cmd.encode('utf-8'))
106106
response = "ok"
107+
elif decoded[1] == 'malformed':
108+
cmd = '["ex",":"]wrong!["ex","smi"]'
109+
print("sending: {}".format(cmd))
110+
self.request.sendall(cmd.encode('utf-8'))
111+
response = "ok"
107112
elif decoded[1] == 'an expr':
108113
# Send an expr request.
109114
cmd = '["expr","setline(\\"$\\", [\\"one\\",\\"two\\",\\"three\\"])"]'

src/testdir/test_channel.vim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ func s:communicate(port)
123123
" check that no job is handled correctly
124124
call assert_equal('no process', string(ch_getjob(handle)))
125125
endif
126-
127126
" Simple string request and reply.
128127
call assert_equal('got it', ch_evalexpr(handle, 'hello!'))
129128

129+
" Malformed command should be ignored.
130+
call assert_equal('ok', ch_evalexpr(handle, 'malformed'))
131+
130132
" Request that triggers sending two ex commands. These will usually be
131133
" handled before getting the response, but it's not guaranteed, thus wait a
132134
" tiny bit for the commands to get executed.

src/version.c

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

749749
static int included_patches[] =
750750
{ /* Add new patch number below this line */
751+
/**/
752+
1616,
751753
/**/
752754
1615,
753755
/**/

0 commit comments

Comments
 (0)