Mercurial > vim
diff src/misc2.c @ 2768:c5e47b752f07 v7.3.160
updated for version 7.3.160
Problem: Unsafe string copying.
Solution: Use vim_strncpy() instead of strcpy(). Use vim_strcat() instead
of strcat().
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Mon, 11 Apr 2011 16:56:35 +0200 |
parents | 4549e0e7fbb6 |
children | 0bef86c5c985 |
line wrap: on
line diff
--- a/src/misc2.c +++ b/src/misc2.c @@ -1647,6 +1647,28 @@ vim_strncpy(to, from, len) } /* + * Like strcat(), but make sure the result fits in "tosize" bytes and is + * always NUL terminated. + */ + void +vim_strcat(to, from, tosize) + char_u *to; + char_u *from; + size_t tosize; +{ + size_t tolen = STRLEN(to); + size_t fromlen = STRLEN(from); + + if (tolen + fromlen + 1 > tosize) + { + mch_memmove(to + tolen, from, tosize - tolen - 1); + to[tosize - 1] = NUL; + } + else + STRCPY(to + tolen, from); +} + +/* * Isolate one part of a string option where parts are separated with * "sep_chars". * The part is copied into "buf[maxlen]".