diff options
author | zeertzjq <zeertzjq@outlook.com> | 2025-03-15 08:14:31 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2025-03-15 08:15:58 +0800 |
commit | ad5bced63798b99d3e423414ac3ca3ebdc02cbc2 (patch) | |
tree | 51924bd4f4dcaa2783a213774b74903d14424cba | |
parent | f1422a313fa57c8c7045163aa209a9fd9166fe5a (diff) | |
download | rneovim-ad5bced63798b99d3e423414ac3ca3ebdc02cbc2.tar.gz rneovim-ad5bced63798b99d3e423414ac3ca3ebdc02cbc2.tar.bz2 rneovim-ad5bced63798b99d3e423414ac3ca3ebdc02cbc2.zip |
vim-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().
https://github.com/vim/vim/commit/386c24cd262edac66a31add2fd989c96c4c2c952
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | src/nvim/path.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c index 6c6a6f58c0..d92b9c0f7e 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 = 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. @@ -745,14 +746,13 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in 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 |