commit 27ec8a1d58282543c4da6ce2c68eb62e0bebde88
parent f3fe5433585320e5313ffa3e9b804ace01a954a1
Author: Joris Vink <joris@coders.se>
Date: Wed, 23 Apr 2014 14:48:29 +0200
Don't let kore_strlcpy() overflow a buffer that is 1 byte long
Diffstat:
src/utils.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/utils.c b/src/utils.c
@@ -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++;
}
}