diff options
author | Romain Izard <romain.izard.pro@gmail.com> | 2011-06-24 11:01:10 +0200 |
---|---|---|
committer | maximilian attems <max@stro.at> | 2011-06-25 09:33:47 +0200 |
commit | 89d86aab5ccacfc25d2aafd13dd12ae9bf37baaf (patch) | |
tree | eaed32aab967d84f4a9a030ba947e0d9255720c2 | |
parent | 0bd18d54159154f4af1c478a854c884cd80ecf0b (diff) | |
download | klibc-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.c | 2 |
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; } |