diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ex_cmds.c | 26 | ||||
-rw-r--r-- | src/nvim/path.c | 17 |
2 files changed, 25 insertions, 18 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 431b608bef..3a551975f3 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4812,9 +4812,13 @@ void fix_help_buffer(void) vimconv_T vc; char_u *cp; - /* Find all "doc/ *.txt" files in this directory. */ - add_pathsep((char *)NameBuff); - STRCAT(NameBuff, "doc/*.??[tx]"); + // Find all "doc/ *.txt" files in this directory. + if (!add_pathsep((char *)NameBuff) + || STRLCAT(NameBuff, "doc/*.??[tx]", + sizeof(NameBuff)) >= MAXPATHL) { + EMSG(_(e_pathtoolong)); + continue; + } // Note: We cannot just do `&NameBuff` because it is a statically sized array // so `NameBuff == &NameBuff` according to C semantics. @@ -4995,13 +4999,13 @@ static void helptags_one(char_u *dir, char_u *ext, char_u *tagfname, return; } - /* - * Open the tags file for writing. - * Do this before scanning through all the files. - */ + // + // Open the tags file for writing. + // Do this before scanning through all the files. + // memcpy(NameBuff, dir, dirlen + 1); - add_pathsep((char *)NameBuff); - if (STRLCAT(NameBuff, tagfname, sizeof(NameBuff)) >= MAXPATHL) { + if (!add_pathsep((char *)NameBuff) + || STRLCAT(NameBuff, tagfname, sizeof(NameBuff)) >= MAXPATHL) { EMSG(_(e_pathtoolong)); return; } @@ -5178,8 +5182,8 @@ static void do_helptags(char_u *dirname, bool add_help_tags) // Get a list of all files in the help directory and in subdirectories. STRLCPY(NameBuff, dirname, sizeof(NameBuff)); - add_pathsep((char *)NameBuff); - if (STRLCAT(NameBuff, "**", MAXPATHL) >= MAXPATHL) { + if (!add_pathsep((char *)NameBuff) + || STRLCAT(NameBuff, "**", sizeof(NameBuff)) >= MAXPATHL) { EMSG(_(e_pathtoolong)); xfree(dirname); return; diff --git a/src/nvim/path.c b/src/nvim/path.c index cdb16dbef1..7e1183d5db 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -391,19 +391,22 @@ char *concat_fnames_realloc(char *fname1, const char *fname2, bool sep) fname2, len2, sep); } -/* - * Add a path separator to a file name, unless it already ends in a path - * separator. - */ -void add_pathsep(char *p) +/// Adds a path separator to a filename, unless it already ends in one. +/// +/// @return `true` if the path separator was added or already existed. +/// `false` if the filename is too long. +bool add_pathsep(char *p) FUNC_ATTR_NONNULL_ALL { const size_t len = strlen(p); - const size_t pathsep_len = sizeof(PATHSEPSTR); - assert(len < MAXPATHL - pathsep_len); if (*p != NUL && !after_pathsep(p, p + len)) { + const size_t pathsep_len = sizeof(PATHSEPSTR); + if (len > MAXPATHL - pathsep_len) { + return false; + } memcpy(p + len, PATHSEPSTR, pathsep_len); } + return true; } /// Get an allocated copy of the full path to a file. |