Module Name: src
Committed By: christos
Date: Sun Apr 6 19:29:25 UTC 2014
Modified Files:
src/lib/libc/ssp: stpcpy_chk.c
Log Message:
fix incorrect bounds check
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/ssp/stpcpy_chk.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/ssp/stpcpy_chk.c
diff -u src/lib/libc/ssp/stpcpy_chk.c:1.4 src/lib/libc/ssp/stpcpy_chk.c:1.5
--- src/lib/libc/ssp/stpcpy_chk.c:1.4 Sat Apr 5 21:13:59 2014
+++ src/lib/libc/ssp/stpcpy_chk.c Sun Apr 6 15:29:25 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: stpcpy_chk.c,v 1.4 2014/04/06 01:13:59 christos Exp $ */
+/* $NetBSD: stpcpy_chk.c,v 1.5 2014/04/06 19:29:25 christos Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: stpcpy_chk.c,v 1.4 2014/04/06 01:13:59 christos Exp $");
+__RCSID("$NetBSD: stpcpy_chk.c,v 1.5 2014/04/06 19:29:25 christos Exp $");
/*LINTLIBRARY*/
@@ -45,11 +45,11 @@ char *__stpcpy_chk(char * __restrict, co
char *
__stpcpy_chk(char * __restrict dst, const char * __restrict src, size_t slen)
{
- size_t len = strlen(src) + 1;
+ size_t len = strlen(src);
- if (len > slen)
+ if (len >= slen)
__chk_fail();
- (void)memcpy(dst, src, len);
- return dst + len - 1;
+ (void)memcpy(dst, src, len + 1);
+ return dst + len;
}