diff options
author | cztchoice <cztchoice@gmail.com> | 2015-07-18 17:27:05 +0800 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-01-23 15:49:36 +0100 |
commit | 6e75bb5cbbf172bf586b3326ac43bad219ae26a3 (patch) | |
tree | 8469ad21d44fa6afa16c95a0a5504dd4bfbf66d0 /src/nvim/ex_cmds.c | |
parent | d4b931deacf61528e902623d38d0f4d314bc1839 (diff) | |
download | rneovim-6e75bb5cbbf172bf586b3326ac43bad219ae26a3.tar.gz rneovim-6e75bb5cbbf172bf586b3326ac43bad219ae26a3.tar.bz2 rneovim-6e75bb5cbbf172bf586b3326ac43bad219ae26a3.zip |
refactor: strlcat instead of str{n}cat.
Add xstrlcat function.
Closes #3042
References #988
References #1069
coverity: 71530, 71531, 71532
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r-- | src/nvim/ex_cmds.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index cf711552be..431b608bef 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4977,8 +4977,12 @@ static void helptags_one(char_u *dir, char_u *ext, char_u *tagfname, // Find all *.txt files. size_t dirlen = STRLCPY(NameBuff, dir, sizeof(NameBuff)); - STRCAT(NameBuff, "/**/*"); // NOLINT - STRCAT(NameBuff, ext); + if (dirlen >= MAXPATHL + || STRLCAT(NameBuff, "/**/*", sizeof(NameBuff)) >= MAXPATHL // NOLINT + || STRLCAT(NameBuff, ext, sizeof(NameBuff)) >= MAXPATHL) { + EMSG(_(e_pathtoolong)); + return; + } // Note: We cannot just do `&NameBuff` because it is a statically sized array // so `NameBuff == &NameBuff` according to C semantics. @@ -4995,9 +4999,12 @@ static void helptags_one(char_u *dir, char_u *ext, char_u *tagfname, * Open the tags file for writing. * Do this before scanning through all the files. */ - STRLCPY(NameBuff, dir, sizeof(NameBuff)); + memcpy(NameBuff, dir, dirlen + 1); add_pathsep((char *)NameBuff); - STRNCAT(NameBuff, tagfname, sizeof(NameBuff) - dirlen - 2); + if (STRLCAT(NameBuff, tagfname, sizeof(NameBuff)) >= MAXPATHL) { + EMSG(_(e_pathtoolong)); + return; + } fd_tags = mch_fopen((char *)NameBuff, "w"); if (fd_tags == NULL) { EMSG2(_("E152: Cannot open %s for writing"), NameBuff); @@ -5172,7 +5179,11 @@ 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); - STRCAT(NameBuff, "**"); + if (STRLCAT(NameBuff, "**", MAXPATHL) >= MAXPATHL) { + EMSG(_(e_pathtoolong)); + xfree(dirname); + return; + } // Note: We cannot just do `&NameBuff` because it is a statically sized array // so `NameBuff == &NameBuff` according to C semantics. |