[klibc] [PATCH 2/2] strndup(): Do not corrupt the memory pool
Romain Izard
romain.izard.pro at gmail.com
Fri Jun 24 02:01:10 PDT 2011
The allocated string may be shorter than the requested length. Always
use the shortest length to write the terminating zero
Signed-off-by: Romain Izard <romain.izard.pro at gmail.com>
---
usr/klibc/strndup.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/usr/klibc/strndup.c b/usr/klibc/strndup.c
index e4814be..20eaa8b 100644
--- a/usr/klibc/strndup.c
+++ b/usr/klibc/strndup.c
@@ -13,6 +13,6 @@ char *strndup(const char *s, size_t n)
return NULL;
memcpy(d, s, l);
- d[n] = '\0';
+ d[l] = '\0';
return d;
}
--
1.7.0.4
More information about the klibc
mailing list