Skip to content

Commit 6076fe1

Browse files
committed
patch 7.4.1264
Problem: Crash when receiving an empty array. Solution: Check for array with wrong number of arguments. (Damien)
1 parent 4d919d7 commit 6076fe1

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed

src/channel.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,9 @@ channel_parse_json(int ch_idx)
688688
ret = json_decode(&reader, &listtv);
689689
if (ret == OK)
690690
{
691-
if (listtv.v_type != VAR_LIST)
691+
/* Only accept the response when it is a list with at least two
692+
* items. */
693+
if (listtv.v_type != VAR_LIST || listtv.vval.v_list->lv_len < 2)
692694
{
693695
/* TODO: give error */
694696
clear_tv(&listtv);
@@ -909,13 +911,6 @@ may_invoke_callback(int idx)
909911
}
910912

911913
list = listtv->vval.v_list;
912-
if (list->lv_len < 2)
913-
{
914-
/* TODO: give error */
915-
clear_tv(listtv);
916-
return FALSE;
917-
}
918-
919914
argv[1] = list->lv_first->li_next->li_tv;
920915
typetv = &list->lv_first->li_tv;
921916
if (typetv->v_type == VAR_STRING)

src/eval.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9875,18 +9875,12 @@ f_ch_sendexpr(typval_T *argvars, typval_T *rettv)
98759875
{
98769876
if (channel_read_json_block(ch_idx, id, &listtv) == OK)
98779877
{
9878-
if (listtv->v_type == VAR_LIST)
9879-
{
9880-
list_T *list = listtv->vval.v_list;
9878+
list_T *list = listtv->vval.v_list;
98819879

9882-
if (list->lv_len == 2)
9883-
{
9884-
/* Move the item from the list and then change the type to
9885-
* avoid the value being freed. */
9886-
*rettv = list->lv_last->li_tv;
9887-
list->lv_last->li_tv.v_type = VAR_NUMBER;
9888-
}
9889-
}
9880+
/* Move the item from the list and then change the type to
9881+
* avoid the value being freed. */
9882+
*rettv = list->lv_last->li_tv;
9883+
list->lv_last->li_tv.v_type = VAR_NUMBER;
98909884
clear_tv(listtv);
98919885
}
98929886
}

src/testdir/test_channel.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ def handle(self):
9393
print("sending: {}".format(cmd))
9494
self.request.sendall(cmd.encode('utf-8'))
9595
response = "ok"
96+
elif decoded[1] == 'empty-request':
97+
cmd = '[]'
98+
print("sending: {}".format(cmd))
99+
self.request.sendall(cmd.encode('utf-8'))
100+
response = "ok"
96101
elif decoded[1] == 'eval-result':
97102
# Send back the last received eval result.
98103
response = last_eval
@@ -123,11 +128,9 @@ class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
123128
server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
124129
ip, port = server.server_address
125130

126-
# Start a thread with the server -- that thread will then start one
127-
# more thread for each request
131+
# Start a thread with the server. That thread will then start a new thread
132+
# for each connection.
128133
server_thread = threading.Thread(target=server.serve_forever)
129-
130-
# Exit the server thread when the main thread terminates
131134
server_thread.start()
132135

133136
# Write the port number in Xportnr, so that the test knows it.

src/version.c

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

743743
static int included_patches[] =
744744
{ /* Add new patch number below this line */
745+
/**/
746+
1264,
745747
/**/
746748
1263,
747749
/**/

0 commit comments

Comments
 (0)