diff options
author | Robert Mustacchi <rm@fingolfin.org> | 2022-08-29 03:03:30 +0000 |
---|---|---|
committer | Robert Mustacchi <rm@fingolfin.org> | 2022-09-06 00:14:41 +0000 |
commit | 4322dd9069f078f823a09309fbdfc08ed9085b8d (patch) | |
tree | 3a5a0f1ebcc14bc804307240d2e502439869458b /usr/src/lib/libc/port | |
parent | a8962f2d3198cddcb94ae1ac2b578f9fbaf9a464 (diff) | |
download | illumos-joyent-4322dd9069f078f823a09309fbdfc08ed9085b8d.tar.gz |
14933 asprintf(3c) is confused by NUL
Reviewed by: Dan McDonald <danmcd@mnx.io>
Reviewed by: Andy Fiddaman <illumos@fiddaman.net>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Garrett D'Amore <garrett@damore.org>
Diffstat (limited to 'usr/src/lib/libc/port')
-rw-r--r-- | usr/src/lib/libc/port/print/asprintf.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/usr/src/lib/libc/port/print/asprintf.c b/usr/src/lib/libc/port/print/asprintf.c index a66d1dee2f..0303369d9b 100644 --- a/usr/src/lib/libc/port/print/asprintf.c +++ b/usr/src/lib/libc/port/print/asprintf.c @@ -5,6 +5,7 @@ /* * Copyright (c) 2004 Darren Tucker. + * Copyright 2022 Oxide Computer Company * * Based originally on asprintf.c from OpenBSD: * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> @@ -32,7 +33,6 @@ #define INIT_SZ 128 -/* VARARGS2 */ int vasprintf(char **str, const char *format, va_list ap) { @@ -49,7 +49,13 @@ vasprintf(char **str, const char *format, va_list ap) len = ret + 1; if ((newstr = malloc(len)) == NULL) return (-1); /* retain errno from malloc() */ - (void) strlcpy(newstr, string, len); + /* + * Prior versions of this used strlcpy. This has two problems. + * One, it doesn't handle embedded '\0' characters. Secondly, + * it's recalculating the length we already know. Please do not + * use a string-based copying function. + */ + (void) memcpy(newstr, string, len); *str = newstr; return (ret); } |