changeset 153:5f206fe8d965

Change strlcpy not to use strncpy. (Adds 24 bytes, but doesn't memset the unused portion of the buffer to 0, which can touch and allocate physical pages for a large virtual mapping.)
author Rob Landley <rob@landley.net>
date Thu, 15 Nov 2007 16:18:33 -0600
parents 28d2042bcc13
children 05d80f4dfdb4
files lib/lib.c
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lib/lib.c	Mon Nov 12 19:24:52 2007 -0600
+++ b/lib/lib.c	Thu Nov 15 16:18:33 2007 -0600
@@ -18,8 +18,12 @@
 // Like strncpy but always null terminated.
 void strlcpy(char *dest, char *src, size_t size)
 {
-	strncpy(dest,src,size);
-	dest[size-1] = 0;
+	int len = strlen(src);
+	if (size--) {
+		if (len > size) len=size;
+		memcpy(dest,src, len);
+		dest[len] = 0;
+	}
 }
 #endif