aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2007-11-15 16:18:33 -0600
committerRob Landley <rob@landley.net>2007-11-15 16:18:33 -0600
commit59f757e4d7162ce24b4630c38460c33196a0bfc5 (patch)
treea22ab30120ad14b516fbb1af9ab78c069498f4c1 /lib
parentce8aae448a43d42d8781a72a67235dba8e977aa0 (diff)
downloadtoybox-59f757e4d7162ce24b4630c38460c33196a0bfc5.tar.gz
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.)
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/lib.c b/lib/lib.c
index ad84dff5..eed72968 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -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