aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Izard <romain.izard.pro@gmail.com>2011-06-24 11:01:10 +0200
committermaximilian attems <max@stro.at>2011-06-25 09:33:47 +0200
commit89d86aab5ccacfc25d2aafd13dd12ae9bf37baaf (patch)
treeeaed32aab967d84f4a9a030ba947e0d9255720c2
parent0bd18d54159154f4af1c478a854c884cd80ecf0b (diff)
downloadklibc-89d86aab5ccacfc25d2aafd13dd12ae9bf37baaf.tar.gz
[klibc] strndup(): Do not corrupt the memory pool
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@gmail.com> Reviewed-by: H. Peter Anvin <hpa@zytor.com> Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r--usr/klibc/strndup.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/usr/klibc/strndup.c b/usr/klibc/strndup.c
index e4814be09e007..20eaa8b5c7f32 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;
}