1
0
forked from aniani/vim

updated for version 7.3.160

Problem:    Unsafe string copying.
Solution:   Use vim_strncpy() instead of strcpy().  Use vim_strcat() instead
            of strcat().
This commit is contained in:
Bram Moolenaar
2011-04-11 16:56:35 +02:00
parent 0d35e91abf
commit ef9d6aa70d
13 changed files with 63 additions and 32 deletions

View File

@@ -1646,6 +1646,28 @@ vim_strncpy(to, from, len)
to[len] = NUL;
}
/*
* 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".