summaryrefslogtreecommitdiff
path: root/usr/src/lib
diff options
context:
space:
mode:
authorDan McDonald <danmcd@mnx.io>2022-09-06 22:57:04 -0400
committerDan McDonald <danmcd@mnx.io>2022-09-06 22:57:04 -0400
commit054936a1c946defd71850a10311181d0f91492c7 (patch)
treecdf21170eab4821fcfa7c90a2bd6aa7214161017 /usr/src/lib
parent27b037a7c4032bcea69b12d1252225a3ea7c755f (diff)
parent4322dd9069f078f823a09309fbdfc08ed9085b8d (diff)
downloadillumos-joyent-release-20220908.tar.gz
[illumos-gate merge]release-20220908
commit 4322dd9069f078f823a09309fbdfc08ed9085b8d 14933 asprintf(3c) is confused by NUL
Diffstat (limited to 'usr/src/lib')
-rw-r--r--usr/src/lib/libc/port/print/asprintf.c10
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);
}