summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/vasprintf.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2017-03-17 14:53:08 +0000
committerderaadt <deraadt@openbsd.org>2017-03-17 14:53:08 +0000
commit977aa0f22cea0809e6a84289ed753ba3f0b53fa7 (patch)
treeedc3a3a21d8bdc826b2eb933725c61be66cc74c9 /lib/libc/stdio/vasprintf.c
parentFix a couple of argument types. (diff)
downloadwireguard-openbsd-977aa0f22cea0809e6a84289ed753ba3f0b53fa7.tar.xz
wireguard-openbsd-977aa0f22cea0809e6a84289ed753ba3f0b53fa7.zip
Use recallocarray() to avoid leaving detritus in memory when resizing
buffers. We don't bother doing this for objects containing pointers, but focus on controllable data. ok millert
Diffstat (limited to 'lib/libc/stdio/vasprintf.c')
-rw-r--r--lib/libc/stdio/vasprintf.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c
index 5aaaadf677b..174d8f4f4c1 100644
--- a/lib/libc/stdio/vasprintf.c
+++ b/lib/libc/stdio/vasprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vasprintf.c,v 1.21 2017/03/16 14:32:02 millert Exp $ */
+/* $OpenBSD: vasprintf.c,v 1.22 2017/03/17 14:53:08 deraadt Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -46,7 +46,9 @@ vasprintf(char **str, const char *fmt, __va_list ap)
*f._p = '\0';
if (ret + 1 > INITIAL_SIZE && ret + 1 < pgsz / 2) {
/* midsize allocations can try to conserve memory */
- unsigned char *_base = realloc(f._bf._base, ret + 1);
+ unsigned char *_base = recallocarray(f._bf._base,
+ f._bf._size + 1, ret + 1, 1);
+
if (_base == NULL)
goto err;
*str = (char *)_base;