summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1998-08-14 21:39:18 +0000
committerderaadt <deraadt@openbsd.org>1998-08-14 21:39:18 +0000
commite512315e955209fedb2d53461c3973f04fc1dd55 (patch)
treeb9010203c21d01e17b517ff226492586563669b8 /lib/libc/stdio
parentrealloc repair (diff)
downloadwireguard-openbsd-e512315e955209fedb2d53461c3973f04fc1dd55.tar.xz
wireguard-openbsd-e512315e955209fedb2d53461c3973f04fc1dd55.zip
realloc repair
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r--lib/libc/stdio/asprintf.c10
-rw-r--r--lib/libc/stdio/fvwrite.c9
-rw-r--r--lib/libc/stdio/vasprintf.c13
-rw-r--r--lib/libc/stdio/vfprintf.c13
4 files changed, 27 insertions, 18 deletions
diff --git a/lib/libc/stdio/asprintf.c b/lib/libc/stdio/asprintf.c
index 1d319ab4896..daca01a016d 100644
--- a/lib/libc/stdio/asprintf.c
+++ b/lib/libc/stdio/asprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asprintf.c,v 1.4 1998/06/21 22:13:46 millert Exp $ */
+/* $OpenBSD: asprintf.c,v 1.5 1998/08/14 21:39:39 deraadt Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -28,7 +28,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: asprintf.c,v 1.4 1998/06/21 22:13:46 millert Exp $";
+static char rcsid[] = "$OpenBSD: asprintf.c,v 1.5 1998/08/14 21:39:39 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -53,6 +53,7 @@ asprintf(str, fmt, va_alist)
int ret;
va_list ap;
FILE f;
+ unsigned char *_base;
#if __STDC__
va_start(ap, fmt);
@@ -71,11 +72,12 @@ asprintf(str, fmt, va_alist)
ret = vfprintf(&f, fmt, ap);
*f._p = '\0';
va_end(ap);
- f._bf._base = realloc(f._bf._base, f._bf._size + 1);
- if (f._bf._base == NULL) {
+ _base = realloc(f._bf._base, f._bf._size + 1);
+ if (_base == NULL) {
errno = ENOMEM;
ret = -1;
}
+ f._bf._base = _base;
*str = (char *)f._bf._base;
return (ret);
}
diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c
index bc73dbb8743..07c4bc7a06d 100644
--- a/lib/libc/stdio/fvwrite.c
+++ b/lib/libc/stdio/fvwrite.c
@@ -35,7 +35,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: fvwrite.c,v 1.6 1997/11/30 01:13:24 millert Exp $";
+static char rcsid[] = "$OpenBSD: fvwrite.c,v 1.7 1998/08/14 21:39:40 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -113,6 +113,7 @@ __sfvwrite(fp, uio)
if ((fp->_flags & (__SALC | __SSTR)) ==
(__SALC | __SSTR) && fp->_w < len) {
size_t blen = fp->_p - fp->_bf._base;
+ unsigned char *_base;
/*
* Alloc an extra 128 bytes (+ 1 for NULL)
@@ -120,10 +121,10 @@ __sfvwrite(fp, uio)
*/
fp->_w = len + 128;
fp->_bf._size = blen + len + 128;
- fp->_bf._base =
- realloc(fp->_bf._base, fp->_bf._size + 1);
- if (fp->_bf._base == NULL)
+ _base = realloc(fp->_bf._base, fp->_bf._size + 1);
+ if (_base == NULL)
goto err;
+ fp->_bf._base = _base;
fp->_p = fp->_bf._base + blen;
}
w = fp->_w;
diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c
index 67e41bd5f18..fc3b2c95e98 100644
--- a/lib/libc/stdio/vasprintf.c
+++ b/lib/libc/stdio/vasprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vasprintf.c,v 1.4 1998/06/21 22:13:47 millert Exp $ */
+/* $OpenBSD: vasprintf.c,v 1.5 1998/08/14 21:39:41 deraadt Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -28,7 +28,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: vasprintf.c,v 1.4 1998/06/21 22:13:47 millert Exp $";
+static char rcsid[] = "$OpenBSD: vasprintf.c,v 1.5 1998/08/14 21:39:41 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -43,6 +43,7 @@ vasprintf(str, fmt, ap)
{
int ret;
FILE f;
+ unsigned char *_base;
f._file = -1;
f._flags = __SWR | __SSTR | __SALC;
@@ -55,11 +56,15 @@ vasprintf(str, fmt, ap)
f._bf._size = f._w = 127; /* Leave room for the NULL */
ret = vfprintf(&f, fmt, ap);
*f._p = '\0';
- f._bf._base = realloc(f._bf._base, f._bf._size + 1);
- if (f._bf._base == NULL) {
+ _base = realloc(f._bf._base, f._bf._size + 1);
+ if (_base == NULL) {
+ if (f._bf._base)
+ free(f._bf._base);
+ f._bf._base = NULL;
errno = ENOMEM;
ret = -1;
}
+ f._bf._base = _base;
*str = (char *)f._bf._base;
return (ret);
}
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index 274f7b9d82f..1a1cf974a25 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -35,7 +35,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: vfprintf.c,v 1.7 1997/07/25 20:30:12 mickey Exp $";
+static char *rcsid = "$OpenBSD: vfprintf.c,v 1.8 1998/08/14 21:39:42 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -60,9 +60,10 @@ static char *rcsid = "$OpenBSD: vfprintf.c,v 1.7 1997/07/25 20:30:12 mickey Exp
#include "local.h"
#include "fvwrite.h"
-static void __find_arguments(const char *fmt0, va_list ap, va_list **argtable);
-static int __grow_type_table(unsigned char **typetable,
- int *tablesize);
+static void __find_arguments __P((const char *fmt0, va_list ap,
+ va_list **argtable));
+static int __grow_type_table __P((unsigned char **typetable,
+ int *tablesize));
/*
* Flush out all the vectors defined by the given uio,
@@ -1068,7 +1069,7 @@ done:
* Increase the size of the type table.
*/
static int
-__grow_type_table (typetable, tablesize)
+__grow_type_table(typetable, tablesize)
unsigned char **typetable;
int *tablesize;
{
@@ -1082,7 +1083,7 @@ __grow_type_table (typetable, tablesize)
} else {
*typetable = (unsigned char *)
realloc (typetable, sizeof (unsigned char) * newsize);
-
+ /* XXX unchecked */
}
memset (&typetable [*tablesize], T_UNUSED, (newsize - *tablesize));