diff options
author | Bryan Cantrill <bryan@joyent.com> | 2018-09-07 23:33:07 +0000 |
---|---|---|
committer | Bryan Cantrill <bryan@joyent.com> | 2018-09-07 23:42:56 +0000 |
commit | db274f7918c54940da065f5800cc2f247bf8f7c2 (patch) | |
tree | 26d8558bd88261848c8d5b9c15f8c730aa0458ee /usr/src/lib/libc | |
parent | 192e1e6405f98e4b0a12f9488793c5dd000f3f7e (diff) | |
download | illumos-joyent-db274f7918c54940da065f5800cc2f247bf8f7c2.tar.gz |
OS-7214 strndup() performs pathologically
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r-- | usr/src/lib/libc/port/gen/strndup.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/usr/src/lib/libc/port/gen/strndup.c b/usr/src/lib/libc/port/gen/strndup.c index a31f60827c..01e6b83a53 100644 --- a/usr/src/lib/libc/port/gen/strndup.c +++ b/usr/src/lib/libc/port/gen/strndup.c @@ -21,10 +21,12 @@ /* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2018 Joyent, Inc. */ #include "lint.h" #include <string.h> +#include <strings.h> #include <stdlib.h> #include <sys/types.h> @@ -38,7 +40,10 @@ strndup(const char *s1, size_t n) char *s2; n = strnlen(s1, n); - if ((s2 = malloc(n + 1)) != NULL) - (void) strlcpy(s2, s1, n + 1); + if ((s2 = malloc(n + 1)) != NULL) { + bcopy(s1, s2, n); + s2[n] = '\0'; + } + return (s2); } |