0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

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().
This commit is contained in:
Bram Moolenaar
2022-05-16 12:37:36 +01:00
parent 5a8fad32ea
commit 386c24cd26
2 changed files with 8 additions and 4 deletions

View File

@@ -3589,6 +3589,7 @@ unix_expandpath(
int didstar) // expanded "**" once already int didstar) // expanded "**" once already
{ {
char_u *buf; char_u *buf;
size_t buflen;
char_u *path_end; char_u *path_end;
char_u *p, *s, *e; char_u *p, *s, *e;
int start_len = gap->ga_len; int start_len = gap->ga_len;
@@ -3612,7 +3613,8 @@ unix_expandpath(
} }
// make room for file name // make room for file name
buf = alloc(STRLEN(path) + BASENAMELEN + 5); buflen = STRLEN(path) + BASENAMELEN + 5;
buf = alloc(buflen);
if (buf == NULL) if (buf == NULL)
return 0; return 0;
@@ -3737,14 +3739,14 @@ unix_expandpath(
{ {
// For "**" in the pattern first go deeper in the tree to // For "**" in the pattern first go deeper in the tree to
// find matches. // find matches.
STRCPY(buf + len, "/**"); vim_snprintf((char *)buf + len, buflen - len,
STRCPY(buf + len + 3, path_end); "/**%s", path_end);
++stardepth; ++stardepth;
(void)unix_expandpath(gap, buf, len + 1, flags, TRUE); (void)unix_expandpath(gap, buf, len + 1, flags, TRUE);
--stardepth; --stardepth;
} }
STRCPY(buf + len, path_end); vim_snprintf((char *)buf + len, buflen - len, "%s", path_end);
if (mch_has_exp_wildcard(path_end)) // handle more wildcards if (mch_has_exp_wildcard(path_end)) // handle more wildcards
{ {
// need to expand another component of the path // need to expand another component of the path

View File

@@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
4963,
/**/ /**/
4962, 4962,
/**/ /**/