summaryrefslogtreecommitdiffstats
path: root/lib/libc/string/strlcat.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1999-06-17 16:28:58 +0000
committermillert <millert@openbsd.org>1999-06-17 16:28:58 +0000
commitab5cd6069740e67f35684c916767a362a8cc43e0 (patch)
tree218e6fd270b3300632573b91b953701c2c642490 /lib/libc/string/strlcat.c
parentfix RCS tags (diff)
downloadwireguard-openbsd-ab5cd6069740e67f35684c916767a362a8cc43e0.tar.xz
wireguard-openbsd-ab5cd6069740e67f35684c916767a362a8cc43e0.zip
When finding the end of dst, never traverse more than siz bytes. This
keeps us from misbehaving if the user gives us a src string that is not NUL-terminated. This is one of those "should not happen" cases but it is good to play it safe. Pointed out by Casper Dik <casper@holland.sun.com>
Diffstat (limited to 'lib/libc/string/strlcat.c')
-rw-r--r--lib/libc/string/strlcat.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/libc/string/strlcat.c b/lib/libc/string/strlcat.c
index 2e8c56926ec..599994edf5a 100644
--- a/lib/libc/string/strlcat.c
+++ b/lib/libc/string/strlcat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: strlcat.c,v 1.1 1998/07/01 01:29:45 millert Exp $ */
+/* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -28,7 +28,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strlcat.c,v 1.1 1998/07/01 01:29:45 millert Exp $";
+static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -50,11 +50,11 @@ size_t strlcat(dst, src, siz)
register size_t n = siz;
size_t dlen;
- /* Find the end of dst and adjust bytes left */
- while (*d != '\0' && n != 0)
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (*d != '\0' && n-- != 0)
d++;
dlen = d - dst;
- n -= dlen;
+ n = siz - dlen;
if (n == 0)
return(dlen + strlen(s));