Don't let kore_strlcpy() overflow a buffer that is 1 byte long

This commit is contained in:
Joris Vink 2014-04-23 14:48:29 +02:00
parent f3fe543358
commit 27ec8a1d58

View File

@ -77,12 +77,16 @@ kore_strlcpy(char *dst, const char *src, size_t len)
{
char *d = dst;
const char *s = src;
const char *end = dst + len - 1;
while ((*d++ = *s++) != '\0') {
if (d == (dst + len - 1)) {
while ((*d = *s) != '\0') {
if (d == end) {
*d = '\0';
break;
}
d++;
s++;
}
}