To: vim_dev@googlegroups.com Subject: Patch 7.4.1616 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1616 Problem: Malformed channel request causes a hang. Solution: Drop malformed message. (Damien) Files: src/channel.c, src/testdir/test_channel.vim, src/testdir/test_channel.py *** ../vim-7.4.1615/src/channel.c 2016-03-19 13:49:39.460590857 +0100 --- src/channel.c 2016-03-20 14:30:14.782823216 +0100 *************** *** 1481,1489 **** * TODO: insert in front */ if (reader.js_buf[reader.js_used] != NUL) { ! channel_save(channel, part, reader.js_buf + reader.js_used, ! (int)(reader.js_end - reader.js_buf) - reader.js_used); ! ret = TRUE; } else ret = FALSE; --- 1481,1497 ---- * TODO: insert in front */ if (reader.js_buf[reader.js_used] != NUL) { ! if (ret == FAIL) ! { ! ch_error(channel, "Decoding failed - discarding input"); ! ret = FALSE; ! } ! else ! { ! channel_save(channel, part, reader.js_buf + reader.js_used, ! (int)(reader.js_end - reader.js_buf) - reader.js_used); ! ret = TRUE; ! } } else ret = FALSE; *************** *** 1586,1597 **** --- 1594,1607 ---- if (STRCMP(cmd, "ex") == 0) { + ch_logs(channel, "Executing ex command '%s'", (char *)arg); do_cmdline_cmd(arg); } else if (STRCMP(cmd, "normal") == 0) { exarg_T ea; + ch_logs(channel, "Executing normal command '%s'", (char *)arg); ea.arg = arg; ea.addr_count = 0; ea.forceit = TRUE; /* no mapping */ *************** *** 1601,1606 **** --- 1611,1617 ---- { exarg_T ea; + ch_log(channel, "redraw"); ea.forceit = *arg != NUL; ex_redraw(&ea); showruler(FALSE); *************** *** 1642,1652 **** /* Don't pollute the display with errors. */ ++emsg_skip; if (!is_call) tv = eval_expr(arg, NULL); ! else if (func_call(arg, &argv[2], NULL, NULL, &res_tv) == OK) ! tv = &res_tv; else ! tv = NULL; if (argv[id_idx].v_type == VAR_NUMBER) { --- 1653,1670 ---- /* Don't pollute the display with errors. */ ++emsg_skip; if (!is_call) + { + ch_logs(channel, "Evaluating expression '%s'", (char *)arg); tv = eval_expr(arg, NULL); ! } else ! { ! ch_logs(channel, "Calling '%s'", (char *)arg); ! if (func_call(arg, &argv[2], NULL, NULL, &res_tv) == OK) ! tv = &res_tv; ! else ! tv = NULL; ! } if (argv[id_idx].v_type == VAR_NUMBER) { *************** *** 1848,1857 **** if (argv[0].v_type == VAR_STRING) { - char_u *cmd = argv[0].vval.v_string; - /* ["cmd", arg] or ["cmd", arg, arg] or ["cmd", arg, arg, arg] */ - ch_logs(channel, "Executing %s command", (char *)cmd); channel_exe_cmd(channel, part, argv); free_tv(listtv); return TRUE; --- 1866,1872 ---- *** ../vim-7.4.1615/src/testdir/test_channel.vim 2016-03-14 23:22:31.219768924 +0100 --- src/testdir/test_channel.vim 2016-03-20 14:24:33.210354928 +0100 *************** *** 123,132 **** " check that no job is handled correctly call assert_equal('no process', string(ch_getjob(handle))) endif - " Simple string request and reply. call assert_equal('got it', ch_evalexpr(handle, 'hello!')) " Request that triggers sending two ex commands. These will usually be " handled before getting the response, but it's not guaranteed, thus wait a " tiny bit for the commands to get executed. --- 123,134 ---- " check that no job is handled correctly call assert_equal('no process', string(ch_getjob(handle))) endif " Simple string request and reply. call assert_equal('got it', ch_evalexpr(handle, 'hello!')) + " Malformed command should be ignored. + call assert_equal('ok', ch_evalexpr(handle, 'malformed')) + " Request that triggers sending two ex commands. These will usually be " handled before getting the response, but it's not guaranteed, thus wait a " tiny bit for the commands to get executed. *** ../vim-7.4.1615/src/testdir/test_channel.py 2016-03-05 20:54:28.216563776 +0100 --- src/testdir/test_channel.py 2016-03-20 13:51:59.442281444 +0100 *************** *** 104,109 **** --- 104,114 ---- print("sending: {}".format(cmd)) self.request.sendall(cmd.encode('utf-8')) response = "ok" + elif decoded[1] == 'malformed': + cmd = '["ex",":"]wrong!["ex","smi"]' + print("sending: {}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" elif decoded[1] == 'an expr': # Send an expr request. cmd = '["expr","setline(\\"$\\", [\\"one\\",\\"two\\",\\"three\\"])"]' *** ../vim-7.4.1615/src/version.c 2016-03-19 23:07:19.052790870 +0100 --- src/version.c 2016-03-20 14:29:06.203533708 +0100 *************** *** 750,751 **** --- 750,753 ---- { /* Add new patch number below this line */ + /**/ + 1616, /**/ -- The sooner you fall behind, the more time you'll have to catch up. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///