[klibc] strndup(): Fix possible null pointer dereference

Directly return NULL if malloc failed.

Reviewed-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: maximilian attems <max@stro.at>
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 @@
 	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;
 }