summary refs log tree commit diff
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2005-10-29 23:48:05 +1000
committerHerbert Xu <herbert@gondor.apana.org.au>2005-10-29 23:48:05 +1000
commita5570fb5a13b49eaf6f7b3db3d9341b596fdfc38 (patch)
tree833c12104854fb8cd7b584376661be77d48ac307
parent[SYSTEM] Added out-of-line ctypes functions for klibc (diff)
downloaddash-a5570fb5a13b49eaf6f7b3db3d9341b596fdfc38.tar.gz
dash-a5570fb5a13b49eaf6f7b3db3d9341b596fdfc38.zip
[SYSTEM] Fixed fallback stpcpy implementation
The implementation has an off-by-one bug.  This results in random memory
corruption.  In one particular case, it caused certain bits of a function
body to go missing.
-rw-r--r--ChangeLog1
-rw-r--r--src/system.c4
2 files changed, 4 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 63dcd87..55efaf8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -22,6 +22,7 @@
 	* Added dummy sysconf implementation.
 	* Include system.h for stpcpy in nodes.c.
 	* Added out-of-line ctypes functions for klibc.
+	* Fixed fallback stpcpy implementation.
 
 2005-10-26  Herbert Xu <herbert@gondor.apana.org.au>
 
diff --git a/src/system.c b/src/system.c
index c6bc52d..5fd6062 100644
--- a/src/system.c
+++ b/src/system.c
@@ -71,7 +71,9 @@ void *mempcpy(void *dest, const void *src, size_t n)
 #ifndef HAVE_STPCPY
 char *stpcpy(char *dest, const char *src)
 {
-	return mempcpy(dest, src, strlen(src) + 1);
+	size_t len = strlen(src);
+	dest[len] = 0;
+	return mempcpy(dest, src, len);
 }
 #endif