]> granicus.if.org Git - vim/commitdiff
patch 7.4.1264 v7.4.1264
authorBram Moolenaar <Bram@vim.org>
Fri, 5 Feb 2016 21:49:56 +0000 (22:49 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 5 Feb 2016 21:49:56 +0000 (22:49 +0100)
Problem:    Crash when receiving an empty array.
Solution:   Check for array with wrong number of arguments. (Damien)

src/channel.c
src/eval.c
src/testdir/test_channel.py
src/version.c

index cab920c22b184d1381722c05b8da0dc817c3ed3f..35875ca9a7ecae4a0613c0f242991bb7c8a2971f 100644 (file)
@@ -688,7 +688,9 @@ channel_parse_json(int ch_idx)
     ret = json_decode(&reader, &listtv);
     if (ret == OK)
     {
-       if (listtv.v_type != VAR_LIST)
+       /* Only accept the response when it is a list with at least two
+        * items. */
+       if (listtv.v_type != VAR_LIST || listtv.vval.v_list->lv_len < 2)
        {
            /* TODO: give error */
            clear_tv(&listtv);
@@ -909,13 +911,6 @@ may_invoke_callback(int idx)
        }
 
        list = listtv->vval.v_list;
-       if (list->lv_len < 2)
-       {
-           /* TODO: give error */
-           clear_tv(listtv);
-           return FALSE;
-       }
-
        argv[1] = list->lv_first->li_next->li_tv;
        typetv = &list->lv_first->li_tv;
        if (typetv->v_type == VAR_STRING)
index 50b1b2aef932f9d1d5bd8e8b757a556a50cb4353..33ec495e83dd0b6d0aab6f3a71e910778bde91bd 100644 (file)
@@ -9875,18 +9875,12 @@ f_ch_sendexpr(typval_T *argvars, typval_T *rettv)
     {
        if (channel_read_json_block(ch_idx, id, &listtv) == OK)
        {
-           if (listtv->v_type == VAR_LIST)
-           {
-               list_T *list = listtv->vval.v_list;
+           list_T *list = listtv->vval.v_list;
 
-               if (list->lv_len == 2)
-               {
-                   /* Move the item from the list and then change the type to
-                    * avoid the value being freed. */
-                   *rettv = list->lv_last->li_tv;
-                   list->lv_last->li_tv.v_type = VAR_NUMBER;
-               }
-           }
+           /* Move the item from the list and then change the type to
+            * avoid the value being freed. */
+           *rettv = list->lv_last->li_tv;
+           list->lv_last->li_tv.v_type = VAR_NUMBER;
            clear_tv(listtv);
        }
     }
index fb75938c1fc948300116797ca2a06a3c8a7d72c5..66b8c5e6650e8a86e92bd3a332798f1d40f3e307 100644 (file)
@@ -93,6 +93,11 @@ class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
                         print("sending: {}".format(cmd))
                         self.request.sendall(cmd.encode('utf-8'))
                         response = "ok"
+                    elif decoded[1] == 'empty-request':
+                        cmd = '[]'
+                        print("sending: {}".format(cmd))
+                        self.request.sendall(cmd.encode('utf-8'))
+                        response = "ok"
                     elif decoded[1] == 'eval-result':
                         # Send back the last received eval result.
                         response = last_eval
@@ -123,11 +128,9 @@ if __name__ == "__main__":
     server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
     ip, port = server.server_address
 
-    # Start a thread with the server -- that thread will then start one
-    # more thread for each request
+    # Start a thread with the server.  That thread will then start a new thread
+    # for each connection.
     server_thread = threading.Thread(target=server.serve_forever)
-
-    # Exit the server thread when the main thread terminates
     server_thread.start()
 
     # Write the port number in Xportnr, so that the test knows it.
index 4f8f454e41ccbe3cd684ffe66d596283882302ce..9939665f6bf8458b0d5292c7427b916cf64c323a 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1264,
 /**/
     1263,
 /**/