diff options
author | maximilian attems <max@stro.at> | 2011-06-10 16:25:51 +0200 |
---|---|---|
committer | maximilian attems <max@stro.at> | 2011-06-14 17:11:17 +0200 |
commit | 9f403cf212ad3964687efe836fa135e45b828e2e (patch) | |
tree | 56c2156fe98cfe078e2e19ae2e6b368a845e05bf | |
parent | d16b1b15a14bfeac86125b250aa72831d2081f00 (diff) | |
download | klibc-9f403cf212ad3964687efe836fa135e45b828e2e.tar.gz |
[klibc] strndup(): Fix possible null pointer dereferenceklibc-1.5.23
Directly return NULL if malloc failed.
Reviewed-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r-- | usr/klibc/strndup.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/usr/klibc/strndup.c b/usr/klibc/strndup.c index 8b5974a3d2437..65afd4440e4da 100644 --- a/usr/klibc/strndup.c +++ b/usr/klibc/strndup.c @@ -10,8 +10,10 @@ char *strndup(const char *s, size_t n) int l = n > strlen(s) ? strlen(s) + 1 : n + 1; char *d = malloc(l); - if (d) - memcpy(d, s, l); + if (!d) + return NULL; + + memcpy(d, s, l); d[n] = '\0'; return d; } |