comparison src/misc1.c @ 10932:141fe140976c v8.0.0355

patch 8.0.0355: using uninitialized memory when 'isfname' is empty commit https://github.com/vim/vim/commit/187a4f28140f10ff833862be7e3ef823d317e1c7 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Feb 23 17:07:14 2017 +0100 patch 8.0.0355: using uninitialized memory when 'isfname' is empty Problem: Using uninitialized memory when 'isfname' is empty. Solution: Don't call getpwnam() without an argument. (Dominique Pelle, closes #1464)
author Christian Brabandt <cb@256bit.org>
date Thu, 23 Feb 2017 17:15:04 +0100
parents 5780bd3a5a7e
children 835604f3c37a
comparison
equal deleted inserted replaced
10931:1f6cfd495a17 10932:141fe140976c
4026 * expand ~user. This is slower and may fail if the shell 4026 * expand ~user. This is slower and may fail if the shell
4027 * does not support ~user (old versions of /bin/sh). 4027 * does not support ~user (old versions of /bin/sh).
4028 */ 4028 */
4029 # if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H) 4029 # if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
4030 { 4030 {
4031 struct passwd *pw;
4032
4033 /* Note: memory allocated by getpwnam() is never freed. 4031 /* Note: memory allocated by getpwnam() is never freed.
4034 * Calling endpwent() apparently doesn't help. */ 4032 * Calling endpwent() apparently doesn't help. */
4035 pw = getpwnam((char *)dst + 1); 4033 struct passwd *pw = (*dst == NUL)
4036 if (pw != NULL) 4034 ? NULL : getpwnam((char *)dst + 1);
4037 var = (char_u *)pw->pw_dir; 4035
4038 else 4036 var = (pw == NULL) ? NULL : (char_u *)pw->pw_dir;
4039 var = NULL;
4040 } 4037 }
4041 if (var == NULL) 4038 if (var == NULL)
4042 # endif 4039 # endif
4043 { 4040 {
4044 expand_T xpc; 4041 expand_T xpc;
9650 # ifdef VMS 9647 # ifdef VMS
9651 vms_remove_version(ffname); 9648 vms_remove_version(ffname);
9652 # endif 9649 # endif
9653 if (match_file_list(p_wig, (*files)[i], ffname)) 9650 if (match_file_list(p_wig, (*files)[i], ffname))
9654 { 9651 {
9655 /* remove this matching files from the list */ 9652 /* remove this matching file from the list */
9656 vim_free((*files)[i]); 9653 vim_free((*files)[i]);
9657 for (j = i; j + 1 < *num_files; ++j) 9654 for (j = i; j + 1 < *num_files; ++j)
9658 (*files)[j] = (*files)[j + 1]; 9655 (*files)[j] = (*files)[j + 1];
9659 --*num_files; 9656 --*num_files;
9660 --i; 9657 --i;
10734 10731
10735 #ifdef SPECIAL_WILDCHAR 10732 #ifdef SPECIAL_WILDCHAR
10736 static int has_special_wildchar(char_u *p); 10733 static int has_special_wildchar(char_u *p);
10737 10734
10738 /* 10735 /*
10739 * Return TRUE if "p" contains a special wildcard character. 10736 * Return TRUE if "p" contains a special wildcard character, one that Vim
10740 * Allowing for escaping. 10737 * cannot expand, requires using a shell.
10741 */ 10738 */
10742 static int 10739 static int
10743 has_special_wildchar(char_u *p) 10740 has_special_wildchar(char_u *p)
10744 { 10741 {
10745 for ( ; *p; mb_ptr_adv(p)) 10742 for ( ; *p; mb_ptr_adv(p))
10746 { 10743 {
10744 /* Allow for escaping. */
10747 if (*p == '\\' && p[1] != NUL) 10745 if (*p == '\\' && p[1] != NUL)
10748 ++p; 10746 ++p;
10749 else if (vim_strchr((char_u *)SPECIAL_WILDCHAR, *p) != NULL) 10747 else if (vim_strchr((char_u *)SPECIAL_WILDCHAR, *p) != NULL)
10750 return TRUE; 10748 return TRUE;
10751 } 10749 }