Displaying 1 result from an estimated 1 matches for "8b5974a".
Did you mean:
85974
2011 Jun 10
0
[PATCH] strndup(): Fix possible null pointer dereference
Directly return NULL if malloc failed.
Signed-off-by: maximilian attems <max at stro.at>
---
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 8b5974a..65afd44 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'...