comparison src/filepath.c @ 28881:3ddaf476a874 v8.2.4963

patch 8.2.4963: expanding path with "/**" may overrun end of buffer Commit: https://github.com/vim/vim/commit/386c24cd262edac66a31add2fd989c96c4c2c952 Author: Bram Moolenaar <Bram@vim.org> Date: Mon May 16 12:37:36 2022 +0100 patch 8.2.4963: expanding path with "/**" may overrun end of buffer Problem: Expanding path with "/**" may overrun end of buffer. Solution: Use vim_snprintf().
author Bram Moolenaar <Bram@vim.org>
date Mon, 16 May 2022 13:45:02 +0200
parents d0241e74bfdb
children 495d55210aac
comparison
equal deleted inserted replaced
28880:58035f47b8c7 28881:3ddaf476a874
3587 int wildoff, 3587 int wildoff,
3588 int flags, // EW_* flags 3588 int flags, // EW_* flags
3589 int didstar) // expanded "**" once already 3589 int didstar) // expanded "**" once already
3590 { 3590 {
3591 char_u *buf; 3591 char_u *buf;
3592 size_t buflen;
3592 char_u *path_end; 3593 char_u *path_end;
3593 char_u *p, *s, *e; 3594 char_u *p, *s, *e;
3594 int start_len = gap->ga_len; 3595 int start_len = gap->ga_len;
3595 char_u *pat; 3596 char_u *pat;
3596 regmatch_T regmatch; 3597 regmatch_T regmatch;
3610 if (got_int) 3611 if (got_int)
3611 return 0; 3612 return 0;
3612 } 3613 }
3613 3614
3614 // make room for file name 3615 // make room for file name
3615 buf = alloc(STRLEN(path) + BASENAMELEN + 5); 3616 buflen = STRLEN(path) + BASENAMELEN + 5;
3617 buf = alloc(buflen);
3616 if (buf == NULL) 3618 if (buf == NULL)
3617 return 0; 3619 return 0;
3618 3620
3619 /* 3621 /*
3620 * Find the first part in the path name that contains a wildcard. 3622 * Find the first part in the path name that contains a wildcard.
3735 3737
3736 if (starstar && stardepth < 100) 3738 if (starstar && stardepth < 100)
3737 { 3739 {
3738 // For "**" in the pattern first go deeper in the tree to 3740 // For "**" in the pattern first go deeper in the tree to
3739 // find matches. 3741 // find matches.
3740 STRCPY(buf + len, "/**"); 3742 vim_snprintf((char *)buf + len, buflen - len,
3741 STRCPY(buf + len + 3, path_end); 3743 "/**%s", path_end);
3742 ++stardepth; 3744 ++stardepth;
3743 (void)unix_expandpath(gap, buf, len + 1, flags, TRUE); 3745 (void)unix_expandpath(gap, buf, len + 1, flags, TRUE);
3744 --stardepth; 3746 --stardepth;
3745 } 3747 }
3746 3748
3747 STRCPY(buf + len, path_end); 3749 vim_snprintf((char *)buf + len, buflen - len, "%s", path_end);
3748 if (mch_has_exp_wildcard(path_end)) // handle more wildcards 3750 if (mch_has_exp_wildcard(path_end)) // handle more wildcards
3749 { 3751 {
3750 // need to expand another component of the path 3752 // need to expand another component of the path
3751 // remove backslashes for the remaining components only 3753 // remove backslashes for the remaining components only
3752 (void)unix_expandpath(gap, buf, len + 1, flags, FALSE); 3754 (void)unix_expandpath(gap, buf, len + 1, flags, FALSE);