diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2018-06-08 02:10:38 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-06-08 08:10:38 +0200 |
commit | be68f218ffef891fe4521d70cf52eceb93ef5d5e (patch) | |
tree | 1c0ed765069549dfe716c9651bcf3106248e453a /src | |
parent | 4871f26c220c5cedbe2f4fbf6cb379da91aef0c3 (diff) | |
download | rneovim-be68f218ffef891fe4521d70cf52eceb93ef5d5e.tar.gz rneovim-be68f218ffef891fe4521d70cf52eceb93ef5d5e.tar.bz2 rneovim-be68f218ffef891fe4521d70cf52eceb93ef5d5e.zip |
vim-patch:8.0.0355: using uninitialized memory when 'isfname' is empty (#8493)
Problem: Using uninitialized memory when 'isfname' is empty.
Solution: Don't call getpwnam() without an argument. (Dominique Pelle,
closes vim/vim#1464)
https://github.com/vim/vim/commit/187a4f28140f10ff833862be7e3ef823d317e1c7
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/os/users.c | 2 | ||||
-rw-r--r-- | src/nvim/path.c | 17 | ||||
-rw-r--r-- | src/nvim/testdir/test_options.vim | 7 |
3 files changed, 17 insertions, 9 deletions
diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index 82bb918f70..7c48ac6e5e 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -76,7 +76,7 @@ char *os_get_user_directory(const char *name) { #if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H) struct passwd *pw; - if (name == NULL) { + if (name == NULL || *name == NUL) { return NULL; } pw = getpwnam(name); // NOLINT(runtime/threadsafe_fn) diff --git a/src/nvim/path.c b/src/nvim/path.c index 4f3f7c0661..61cfaea84a 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1097,17 +1097,18 @@ static bool has_env_var(char_u *p) } #ifdef SPECIAL_WILDCHAR -/* - * Return TRUE if "p" contains a special wildcard character. - * Allowing for escaping. - */ + +// Return TRUE if "p" contains a special wildcard character, one that Vim +// cannot expand, requires using a shell. static bool has_special_wildchar(char_u *p) { for (; *p; mb_ptr_adv(p)) { - if (*p == '\\' && p[1] != NUL) - ++p; - else if (vim_strchr((char_u *)SPECIAL_WILDCHAR, *p) != NULL) + // Allow for escaping + if (*p == '\\' && p[1] != NUL) { + p++; + } else if (vim_strchr((char_u *)SPECIAL_WILDCHAR, *p) != NULL) { return true; + } } return false; } @@ -2033,7 +2034,7 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_files, char_u ***files, break; } if (match_file_list(p_wig, (*files)[i], ffname)) { - // remove this matching files from the list + // remove this matching file from the list xfree((*files)[i]); for (j = i; j + 1 < *num_files; j++) { (*files)[j] = (*files)[j + 1]; diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index eb42e35bd3..5ae8528ee9 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -22,6 +22,13 @@ function! Test_whichwrap() set whichwrap& endfunction +function! Test_isfname() + " This used to cause Vim to access uninitialized memory. + set isfname= + call assert_equal("~X", expand("~X")) + set isfname& +endfunction + function! Test_options() let caught = 'ok' try |