From c8561ecf268c498b41eb36c18f3eda1557b7bdc1 Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 12 Feb 2016 16:29:05 +0900 Subject: vim-patch:7.4.831 Problem: When expanding `=expr` on the command line and encountering an error, the command is executed anyway. Solution: Bail out when an error is detected. https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745 --- src/nvim/path.c | 30 +++++++++++++++--------------- src/nvim/version.c | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/nvim/path.c b/src/nvim/path.c index e0e5f19911..75b34339dd 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1117,6 +1117,7 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u *p; static bool recursive = false; int add_pat; + bool retval = OK; bool did_expand_in_path = false; /* @@ -1158,12 +1159,13 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, add_pat = -1; p = pat[i]; - if (vim_backtick(p)) + if (vim_backtick(p)) { add_pat = expand_backtick(&ga, p, flags); - else { - /* - * First expand environment variables, "~/" and "~user/". - */ + if (add_pat == -1) { + retval = FAIL; + } + } else { + // First expand environment variables, "~/" and "~user/". if (has_env_var(p) || *p == '~') { p = expand_env_save_opt(p, true); if (p == NULL) @@ -1234,7 +1236,7 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, recursive = false; - return (ga.ga_data != NULL) ? OK : FAIL; + return (ga.ga_data != NULL) ? retval : FAIL; } @@ -1246,13 +1248,10 @@ static int vim_backtick(char_u *p) return *p == '`' && *(p + 1) != NUL && *(p + STRLEN(p) - 1) == '`'; } -/* - * Expand an item in `backticks` by executing it as a command. - * Currently only works when pat[] starts and ends with a `. - * Returns number of file names found. - */ -static int -expand_backtick ( +// Expand an item in `backticks` by executing it as a command. +// Currently only works when pat[] starts and ends with a `. +// Returns number of file names found, -1 if an error is encountered. +static int expand_backtick( garray_T *gap, char_u *pat, int flags /* EW_* flags */ @@ -1273,8 +1272,9 @@ expand_backtick ( buffer = get_cmd_output(cmd, NULL, (flags & EW_SILENT) ? kShellOptSilent : 0, NULL); xfree(cmd); - if (buffer == NULL) - return 0; + if (buffer == NULL) { + return -1; + } cmd = buffer; while (*cmd != NUL) { diff --git a/src/nvim/version.c b/src/nvim/version.c index 7d4b8982cd..6fdad105e4 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -459,7 +459,7 @@ static int included_patches[] = { 834, 833, // 832, - // 831, + 831, 830, // 829 NA 828, -- cgit From 6ea1047585664608cb42e007ba87ad86109ae3f8 Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 12 Feb 2016 22:59:34 +0900 Subject: vim-patch:7.4.832 Problem: $HOME in `=$HOME . '/.vimrc'` is expanded too early. Solution: Skip over `=expr` when expanding environment names. https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3 --- To reproduce: ```sh nvim -u NONE -c 'e `=$HOME . "/.vimrc"`' ``` --- src/nvim/os/env.c | 19 ++++++++++++++++++- src/nvim/version.c | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index c1804067e9..ea0e992fe2 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -262,8 +262,25 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, startstr_len = (int)STRLEN(startstr); src = skipwhite(srcp); - --dstlen; // leave one char space for "\," + dstlen--; // leave one char space for "\," while (*src && dstlen > 0) { + // Skip over `=expr`. + if (src[0] == '`' && src[1] == '=') { + var = src; + src += 2; + (void)skip_expr(&src); + if (*src == '`') { + src++; + } + size_t len = (size_t)(src - var); + if (len > (size_t)dstlen) { + len = (size_t)dstlen; + } + memcpy((char *)dst, (char *)var, len); + dst += len; + dstlen -= len; + continue; + } copy_char = true; if ((*src == '$') || (*src == '~' && at_start)) { mustfree = false; diff --git a/src/nvim/version.c b/src/nvim/version.c index 6fdad105e4..7f400773b0 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -458,7 +458,7 @@ static int included_patches[] = { 835, 834, 833, - // 832, + 832, 831, 830, // 829 NA -- cgit From 6bbd149e9812161a736863f68400ff394e649b5e Mon Sep 17 00:00:00 2001 From: watiko Date: Sat, 13 Feb 2016 13:21:44 +0900 Subject: vim-patch:7.4.845 Problem: Compiler warning for possible loss of data. Solution: Add a type cast. (Erich Ritz) https://github.com/vim/vim/commit/5df1ed2de3fa9dcace996b9a0a4c9b3cea79cf1e --- src/nvim/os/env.c | 2 +- src/nvim/version.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index ea0e992fe2..41ce8ddbc2 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -278,7 +278,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, } memcpy((char *)dst, (char *)var, len); dst += len; - dstlen -= len; + dstlen -= (int)len; continue; } copy_char = true; diff --git a/src/nvim/version.c b/src/nvim/version.c index 7f400773b0..a3ada277b7 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -445,7 +445,7 @@ static int included_patches[] = { 848, 847, // 846 NA - // 845, + 845, 844, 843, // 842 NA -- cgit From d6c894efaf81032753f74b943c138c53e0d1fcaf Mon Sep 17 00:00:00 2001 From: watiko Date: Sat, 13 Feb 2016 10:52:00 +0900 Subject: vim-patch:7.4.903 Problem: MS-Windows: When 'encoding' differs from the current code page, expandinig wildcards may cause illegal memory access. Solution: Allocate a longer buffer. (Ken Takata) https://github.com/vim/vim/commit/7314efd87d8c4095229bdc2867a553c36c064918 --- src/nvim/path.c | 5 +++-- src/nvim/version.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/path.c b/src/nvim/path.c index 75b34339dd..f22e0af4f3 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -556,8 +556,9 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, return 0; } - /* make room for file name */ - buf = xmalloc(STRLEN(path) + BASENAMELEN + 5); + // Make room for file name. When doing encoding conversion the actual + // length may be quite a bit longer, thus use the maximum possible length. + buf = xmalloc(MAXPATHL); /* * Find the first part in the path name that contains a wildcard. diff --git a/src/nvim/version.c b/src/nvim/version.c index a3ada277b7..fbace9ec93 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -387,7 +387,7 @@ static int included_patches[] = { // 906 NA // 905, // 904, - // 903, + 903, // 902 NA // 901, // 900 NA -- cgit From 693bf1dafb2ab07d972ed750d8e8f247ecf2db16 Mon Sep 17 00:00:00 2001 From: watiko Date: Sun, 21 Feb 2016 22:07:42 +0900 Subject: path.c: Fulfill the `@returns` conditions Original-author: oni-link --- src/nvim/path.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/path.c b/src/nvim/path.c index f22e0af4f3..5cd93ab811 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1118,7 +1118,6 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u *p; static bool recursive = false; int add_pat; - bool retval = OK; bool did_expand_in_path = false; /* @@ -1163,7 +1162,11 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, if (vim_backtick(p)) { add_pat = expand_backtick(&ga, p, flags); if (add_pat == -1) { - retval = FAIL; + recursive = false; + FreeWild(ga.ga_len, (char_u **)ga.ga_data); + *num_file = 0; + *file = NULL; + return FAIL; } } else { // First expand environment variables, "~/" and "~user/". @@ -1237,7 +1240,7 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, recursive = false; - return (ga.ga_data != NULL) ? retval : FAIL; + return (ga.ga_data != NULL) ? OK : FAIL; } -- cgit