From d4fc674024762a0729bebec8d9e6c204cd034af2 Mon Sep 17 00:00:00 2001 From: Asanka Herath Date: Tue, 24 Aug 2010 00:04:17 -0400 Subject: [PATCH] strlcat() isn't supposed to access *dst past dst_sz Try not to do that on platforms where we can avoid it. --- lib/roken/strlcat.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/roken/strlcat.c b/lib/roken/strlcat.c index 0b676ef98..e8fe1b781 100644 --- a/lib/roken/strlcat.c +++ b/lib/roken/strlcat.c @@ -39,9 +39,16 @@ ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcat (char *dst, const char *src, size_t dst_sz) { - size_t len = strlen(dst); + size_t len; +#if defined(_MSC_VER) && _MSC_VER >= 1400 + len = strnlen_s(dst, dst_sz); +#elif defined(HAVE_STRNLEN) + len = strnlen(dst, dst_sz); +#else + len = strlen(dst); +#endif - if (dst_sz < len) + if (dst_sz <= len) /* the total size of dst is less than the string it contains; this could be considered bad input, but we might as well handle it */