diff options
author | zeertzjq <zeertzjq@outlook.com> | 2025-03-15 08:38:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-15 08:38:07 +0800 |
commit | e7627db35fb04fb70934366237ae59de38792bc5 (patch) | |
tree | e6b9abeb67585db4772efd915461855efd147347 | |
parent | f1422a313fa57c8c7045163aa209a9fd9166fe5a (diff) | |
parent | b0b61c42b3abc9fbbe7f3b06914f8022a6154598 (diff) | |
download | rneovim-e7627db35fb04fb70934366237ae59de38792bc5.tar.gz rneovim-e7627db35fb04fb70934366237ae59de38792bc5.tar.bz2 rneovim-e7627db35fb04fb70934366237ae59de38792bc5.zip |
Merge pull request #32895 from zeertzjq/vim-8.2.4963
vim-patch: buffer overflow when expanding long file name
-rw-r--r-- | src/nvim/path.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c index 6c6a6f58c0..7d623261d2 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -627,7 +627,8 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in // Make room for file name. When doing encoding conversion the actual // length may be quite a bit longer, thus use the maximum possible length. - char *buf = xmalloc(MAXPATHL); + const size_t buflen = strlen(path) + MAXPATHL; + char *buf = xmalloc(buflen); // Find the first part in the path name that contains a wildcard. // When EW_ICASE is set every letter is considered to be a wildcard. @@ -739,20 +740,19 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in && ((regmatch.regprog != NULL && vim_regexec(®match, name, 0)) || ((flags & EW_NOTWILD) && path_fnamencmp(path + (s - buf), name, (size_t)(e - s)) == 0))) { - STRCPY(s, name); + xstrlcpy(s, name, buflen - (size_t)(s - buf)); len = strlen(buf); if (starstar && stardepth < 100) { // For "**" in the pattern first go deeper in the tree to // find matches. - STRCPY(buf + len, "/**"); // NOLINT - STRCPY(buf + len + 3, path_end); + vim_snprintf(buf + len, buflen - len, "/**%s", path_end); // NOLINT stardepth++; do_path_expand(gap, buf, len + 1, flags, true); stardepth--; } - STRCPY(buf + len, path_end); + vim_snprintf(buf + len, buflen - len, "%s", path_end); if (path_has_exp_wildcard(path_end)) { // handle more wildcards // need to expand another component of the path // remove backslashes for the remaining components only |