summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/open_memstream.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/open_memstream.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/open_memstream.c')
-rw-r--r--lib/libc/stdio/open_memstream.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/libc/stdio/open_memstream.c b/lib/libc/stdio/open_memstream.c
index f708acc5032..131d4e08e13 100644
--- a/lib/libc/stdio/open_memstream.c
+++ b/lib/libc/stdio/open_memstream.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: open_memstream.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
+/* $OpenBSD: open_memstream.c,v 1.7 2017/03/17 14:53:08 deraadt Exp $ */
/*
* Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org>
@@ -50,7 +50,7 @@ memstream_write(void *v, const char *b, int l)
if (sz < end + 1)
sz = end + 1;
- p = realloc(st->string, sz);
+ p = recallocarray(st->string, st->size, sz, 1);
if (!p)
return (-1);
bzero(p + st->size, sz - st->size);