comparison src/terminal.c @ 13109:fb1b162cdcf6 v8.0.1429

patch 8.0.1429: crash when calling term_start() with empty argument commit https://github.com/vim/vim/commit/ede35bbbd05306097bf3f4d603f2248ed1f4c5f1 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 26 20:05:18 2018 +0100 patch 8.0.1429: crash when calling term_start() with empty argument Problem: Crash when calling term_start() with empty argument. Solution: Check for invalid argument. (Yasuhiro Matsomoto, closes https://github.com/vim/vim/issues/2503) Fix memory leak.
author Christian Brabandt <cb@256bit.org>
date Fri, 26 Jan 2018 20:15:06 +0100
parents 6f98a5fd0c19
children 149347fda678
comparison
equal deleted inserted replaced
13108:ece995ea03df 13109:fb1b162cdcf6
40 * TODO: 40 * TODO:
41 * - When using 'termguicolors' still use the 16 ANSI colors as-is. Helps for 41 * - When using 'termguicolors' still use the 16 ANSI colors as-is. Helps for
42 * a job that uses 16 colors while Vim is using > 256. 42 * a job that uses 16 colors while Vim is using > 256.
43 * - in GUI vertical split causes problems. Cursor is flickering. (Hirohito 43 * - in GUI vertical split causes problems. Cursor is flickering. (Hirohito
44 * Higashi, 2017 Sep 19) 44 * Higashi, 2017 Sep 19)
45 * - Trigger TerminalOpen event? #2422 patch in #2484
45 * - Shift-Tab does not work. 46 * - Shift-Tab does not work.
46 * - after resizing windows overlap. (Boris Staletic, #2164) 47 * - after resizing windows overlap. (Boris Staletic, #2164)
47 * - Redirecting output does not work on MS-Windows, Test_terminal_redir_file() 48 * - Redirecting output does not work on MS-Windows, Test_terminal_redir_file()
48 * is disabled. 49 * is disabled.
49 * - cursor blinks in terminal on widows with a timer. (xtal8, #2142) 50 * - cursor blinks in terminal on widows with a timer. (xtal8, #2142)
60 * command? 61 * command?
61 * - implement term_setsize() 62 * - implement term_setsize()
62 * - add test for giving error for invalid 'termsize' value. 63 * - add test for giving error for invalid 'termsize' value.
63 * - support minimal size when 'termsize' is "rows*cols". 64 * - support minimal size when 'termsize' is "rows*cols".
64 * - support minimal size when 'termsize' is empty? 65 * - support minimal size when 'termsize' is empty?
66 * - if the job in the terminal does not support the mouse, we can use the
67 * mouse in the Terminal window for copy/paste and scrolling.
65 * - GUI: when using tabs, focus in terminal, click on tab does not work. 68 * - GUI: when using tabs, focus in terminal, click on tab does not work.
66 * - GUI: when 'confirm' is set and trying to exit Vim, dialog offers to save 69 * - GUI: when 'confirm' is set and trying to exit Vim, dialog offers to save
67 * changes to "!shell". 70 * changes to "!shell".
68 * (justrajdeep, 2017 Aug 22) 71 * (justrajdeep, 2017 Aug 22)
69 * - Redrawing is slow with Athena and Motif. Also other GUI? (Ramel Eshed) 72 * - Redrawing is slow with Athena and Motif. Also other GUI? (Ramel Eshed)
70 * - For the GUI fill termios with default values, perhaps like pangoterm: 73 * - For the GUI fill termios with default values, perhaps like pangoterm:
71 * http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134 74 * http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134
72 * - if the job in the terminal does not support the mouse, we can use the
73 * mouse in the Terminal window for copy/paste.
74 * - when 'encoding' is not utf-8, or the job is using another encoding, setup 75 * - when 'encoding' is not utf-8, or the job is using another encoding, setup
75 * conversions. 76 * conversions.
76 * - In the GUI use a terminal emulator for :!cmd. Make the height the same as 77 * - In the GUI use a terminal emulator for :!cmd. Make the height the same as
77 * the window and position it higher up when it gets filled, so it looks like 78 * the window and position it higher up when it gets filled, so it looks like
78 * the text scrolls up. 79 * the text scrolls up.
3386 HANDLE child_process_handle; 3387 HANDLE child_process_handle;
3387 HANDLE child_thread_handle; 3388 HANDLE child_thread_handle;
3388 void *winpty_err; 3389 void *winpty_err;
3389 void *spawn_config = NULL; 3390 void *spawn_config = NULL;
3390 garray_T ga_cmd, ga_env; 3391 garray_T ga_cmd, ga_env;
3391 char_u *cmd; 3392 char_u *cmd = NULL;
3392 3393
3393 if (dyn_winpty_init(TRUE) == FAIL) 3394 if (dyn_winpty_init(TRUE) == FAIL)
3394 return FAIL; 3395 return FAIL;
3396 ga_init2(&ga_cmd, (int)sizeof(char*), 20);
3397 ga_init2(&ga_env, (int)sizeof(char*), 20);
3395 3398
3396 if (argvar->v_type == VAR_STRING) 3399 if (argvar->v_type == VAR_STRING)
3400 {
3397 cmd = argvar->vval.v_string; 3401 cmd = argvar->vval.v_string;
3398 else 3402 }
3399 { 3403 else if (argvar->v_type == VAR_LIST)
3400 ga_init2(&ga_cmd, (int)sizeof(char*), 20); 3404 {
3401 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL) 3405 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL)
3402 goto failed; 3406 goto failed;
3403 cmd = ga_cmd.ga_data; 3407 cmd = ga_cmd.ga_data;
3404 } 3408 }
3409 if (cmd == NULL || *cmd == NUL)
3410 {
3411 EMSG(_(e_invarg));
3412 goto failed;
3413 }
3405 3414
3406 cmd_wchar = enc_to_utf16(cmd, NULL); 3415 cmd_wchar = enc_to_utf16(cmd, NULL);
3416 ga_clear(&ga_cmd);
3407 if (cmd_wchar == NULL) 3417 if (cmd_wchar == NULL)
3408 return FAIL; 3418 goto failed;
3409 if (opt->jo_cwd != NULL) 3419 if (opt->jo_cwd != NULL)
3410 cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL); 3420 cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL);
3411 3421
3412 ga_init2(&ga_env, (int)sizeof(char*), 20);
3413 win32_build_env(opt->jo_env, &ga_env, TRUE); 3422 win32_build_env(opt->jo_env, &ga_env, TRUE);
3414 env_wchar = ga_env.ga_data; 3423 env_wchar = ga_env.ga_data;
3415 3424
3416 job = job_alloc(); 3425 job = job_alloc();
3417 if (job == NULL) 3426 if (job == NULL)
3488 } 3497 }
3489 3498
3490 winpty_spawn_config_free(spawn_config); 3499 winpty_spawn_config_free(spawn_config);
3491 vim_free(cmd_wchar); 3500 vim_free(cmd_wchar);
3492 vim_free(cwd_wchar); 3501 vim_free(cwd_wchar);
3502 vim_free(env_wchar);
3493 3503
3494 create_vterm(term, term->tl_rows, term->tl_cols); 3504 create_vterm(term, term->tl_rows, term->tl_cols);
3495 3505
3496 channel_set_job(channel, job, opt); 3506 channel_set_job(channel, job, opt);
3497 job_set_options(job, opt); 3507 job_set_options(job, opt);
3509 term->tl_job = job; 3519 term->tl_job = job;
3510 3520
3511 return OK; 3521 return OK;
3512 3522
3513 failed: 3523 failed:
3514 if (argvar->v_type == VAR_LIST) 3524 ga_clear(&ga_cmd);
3515 vim_free(ga_cmd.ga_data); 3525 ga_clear(&ga_env);
3516 vim_free(ga_env.ga_data);
3517 vim_free(cmd_wchar); 3526 vim_free(cmd_wchar);
3518 vim_free(cwd_wchar); 3527 vim_free(cwd_wchar);
3519 if (spawn_config != NULL) 3528 if (spawn_config != NULL)
3520 winpty_spawn_config_free(spawn_config); 3529 winpty_spawn_config_free(spawn_config);
3521 if (channel != NULL) 3530 if (channel != NULL)