summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/db/btree/bt_overflow.c8
-rw-r--r--lib/libc/db/recno/rec_get.c20
-rw-r--r--lib/libc/db/recno/rec_put.c8
-rw-r--r--lib/libc/gen/exec.c5
-rw-r--r--lib/libc/gen/fts.c25
-rw-r--r--lib/libc/gen/getcap.c65
-rw-r--r--lib/libc/gen/getcwd.c14
-rw-r--r--lib/libc/gen/getnetgrent.c15
-rw-r--r--lib/libc/gen/getpwent.c13
-rw-r--r--lib/libc/gen/glob.c7
-rw-r--r--lib/libc/gen/opendir.c10
-rw-r--r--lib/libc/gen/scandir.c12
-rw-r--r--lib/libc/gen/setmode.c10
-rw-r--r--lib/libc/regex/regcomp.c13
-rw-r--r--lib/libc/rpc/get_myaddress.c11
-rw-r--r--lib/libc/rpc/pmap_rmt.c12
-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
-rw-r--r--lib/libc/time/ialloc.c4
-rw-r--r--lib/libc/time/strftime.c12
22 files changed, 219 insertions, 90 deletions
diff --git a/lib/libc/db/btree/bt_overflow.c b/lib/libc/db/btree/bt_overflow.c
index f87d01ad5c2..23876f1d6fe 100644
--- a/lib/libc/db/btree/bt_overflow.c
+++ b/lib/libc/db/btree/bt_overflow.c
@@ -35,7 +35,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: bt_overflow.c,v 1.3 1996/08/19 08:20:09 tholo Exp $";
+static char rcsid[] = "$OpenBSD: bt_overflow.c,v 1.4 1998/08/14 21:39:18 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -88,6 +88,7 @@ __ovfl_get(t, p, ssz, buf, bufsz)
pgno_t pg;
size_t nb, plen;
u_int32_t sz;
+ void *tp;
memmove(&pg, p, sizeof(pgno_t));
memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t));
@@ -99,9 +100,10 @@ __ovfl_get(t, p, ssz, buf, bufsz)
#endif
/* Make the buffer bigger as necessary. */
if (*bufsz < sz) {
- *buf = (char *)(*buf == NULL ? malloc(sz) : realloc(*buf, sz));
- if (*buf == NULL)
+ tp = (char *)(*buf == NULL ? malloc(sz) : realloc(*buf, sz));
+ if (tp == NULL)
return (RET_ERROR);
+ *buf = tp;
*bufsz = sz;
}
diff --git a/lib/libc/db/recno/rec_get.c b/lib/libc/db/recno/rec_get.c
index 9d63d307640..d043174a174 100644
--- a/lib/libc/db/recno/rec_get.c
+++ b/lib/libc/db/recno/rec_get.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: rec_get.c,v 1.3 1996/08/19 08:21:03 tholo Exp $";
+static char rcsid[] = "$OpenBSD: rec_get.c,v 1.4 1998/08/14 21:39:20 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -128,13 +128,15 @@ __rec_fpipe(t, top)
size_t len;
int ch;
u_char *p;
+ void *tp;
if (t->bt_rdata.size < t->bt_reclen) {
- t->bt_rdata.data = t->bt_rdata.data == NULL ?
+ tp = t->bt_rdata.data == NULL ?
malloc(t->bt_reclen) :
realloc(t->bt_rdata.data, t->bt_reclen);
- if (t->bt_rdata.data == NULL)
+ if (tp == NULL)
return (RET_ERROR);
+ t->bt_rdata.data = tp;
t->bt_rdata.size = t->bt_reclen;
}
data.data = t->bt_rdata.data;
@@ -185,6 +187,7 @@ __rec_vpipe(t, top)
size_t sz;
int bval, ch;
u_char *p;
+ void *tp;
bval = t->bt_bval;
for (nrec = t->bt_nrecs; nrec < top; ++nrec) {
@@ -203,11 +206,12 @@ __rec_vpipe(t, top)
if (sz == 0) {
len = p - (u_char *)t->bt_rdata.data;
t->bt_rdata.size += (sz = 256);
- t->bt_rdata.data = t->bt_rdata.data == NULL ?
+ tp = t->bt_rdata.data == NULL ?
malloc(t->bt_rdata.size) :
realloc(t->bt_rdata.data, t->bt_rdata.size);
- if (t->bt_rdata.data == NULL)
+ if (tp == NULL)
return (RET_ERROR);
+ t->bt_rdata.data = tp;
p = (u_char *)t->bt_rdata.data + len;
}
}
@@ -240,13 +244,15 @@ __rec_fmap(t, top)
recno_t nrec;
u_char *sp, *ep, *p;
size_t len;
+ void *tp;
if (t->bt_rdata.size < t->bt_reclen) {
- t->bt_rdata.data = t->bt_rdata.data == NULL ?
+ tp = t->bt_rdata.data == NULL ?
malloc(t->bt_reclen) :
realloc(t->bt_rdata.data, t->bt_reclen);
- if (t->bt_rdata.data == NULL)
+ if (tp == NULL)
return (RET_ERROR);
+ t->bt_rdata.data = tp;
t->bt_rdata.size = t->bt_reclen;
}
data.data = t->bt_rdata.data;
diff --git a/lib/libc/db/recno/rec_put.c b/lib/libc/db/recno/rec_put.c
index f9a2fc3d441..1cb617b46cc 100644
--- a/lib/libc/db/recno/rec_put.c
+++ b/lib/libc/db/recno/rec_put.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: rec_put.c,v 1.3 1996/08/19 08:21:06 tholo Exp $";
+static char rcsid[] = "$OpenBSD: rec_put.c,v 1.4 1998/08/14 21:39:21 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -69,6 +69,7 @@ __rec_put(dbp, key, data, flags)
DBT fdata, tdata;
recno_t nrec;
int status;
+ void *tp;
t = dbp->internal;
@@ -88,11 +89,12 @@ __rec_put(dbp, key, data, flags)
goto einval;
if (t->bt_rdata.size < t->bt_reclen) {
- t->bt_rdata.data = t->bt_rdata.data == NULL ?
+ tp = t->bt_rdata.data == NULL ?
malloc(t->bt_reclen) :
realloc(t->bt_rdata.data, t->bt_reclen);
- if (t->bt_rdata.data == NULL)
+ if (tp == NULL)
return (RET_ERROR);
+ t->bt_rdata.data = tp;
t->bt_rdata.size = t->bt_reclen;
}
memmove(t->bt_rdata.data, data->data, data->size);
diff --git a/lib/libc/gen/exec.c b/lib/libc/gen/exec.c
index 3b4bd31a713..98d4a46776b 100644
--- a/lib/libc/gen/exec.c
+++ b/lib/libc/gen/exec.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: exec.c,v 1.7 1997/09/20 09:46:10 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: exec.c,v 1.8 1998/08/14 21:39:23 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -68,7 +68,8 @@ buildargv(ap, arg, envpp)
memsize *= 2; /* Ramp up fast. */
nargv = realloc(argv, memsize * sizeof(char *));
if (nargv == NULL) {
- free(argv);
+ if (argv)
+ free(argv);
return (NULL);
}
argv = nargv;
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
index a2489d3f333..cfec7796178 100644
--- a/lib/libc/gen/fts.c
+++ b/lib/libc/gen/fts.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fts.c,v 1.16 1998/07/03 01:10:27 deraadt Exp $ */
+/* $OpenBSD: fts.c,v 1.17 1998/08/14 21:39:24 deraadt Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
#else
-static char rcsid[] = "$OpenBSD: fts.c,v 1.16 1998/07/03 01:10:27 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: fts.c,v 1.17 1998/08/14 21:39:24 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -905,12 +905,18 @@ fts_sort(sp, head, nitems)
* 40 so don't realloc one entry at a time.
*/
if (nitems > sp->fts_nitems) {
+ struct _ftsent **a;
+
sp->fts_nitems = nitems + 40;
- if ((sp->fts_array = realloc(sp->fts_array,
+ if ((a = realloc(sp->fts_array,
(size_t)(sp->fts_nitems * sizeof(FTSENT *)))) == NULL) {
+ if (sp->fts_array)
+ free(sp->fts_array);
+ sp->fts_array = NULL;
sp->fts_nitems = 0;
return (head);
}
+ sp->fts_array = a;
}
for (ap = sp->fts_array, p = head; p; p = p->fts_link)
*ap++ = p;
@@ -984,9 +990,18 @@ fts_palloc(sp, more)
FTS *sp;
size_t more;
{
+ char *p;
+
sp->fts_pathlen += more + 256;
- sp->fts_path = realloc(sp->fts_path, (size_t)sp->fts_pathlen);
- return (sp->fts_path == NULL);
+ p = realloc(sp->fts_path, (size_t)sp->fts_pathlen);
+ if (p == NULL) {
+ if (sp->fts_path)
+ free(sp->fts_path);
+ sp->fts_path = NULL;
+ return (0);
+ }
+ sp->fts_path = p;
+ return (1);
}
/*
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c
index fa188625975..f65f660f425 100644
--- a/lib/libc/gen/getcap.c
+++ b/lib/libc/gen/getcap.c
@@ -35,7 +35,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getcap.c,v 1.14 1998/03/19 01:00:55 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: getcap.c,v 1.15 1998/08/14 21:39:25 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -346,16 +346,20 @@ getent(cap, len, db_array, fd, name, depth, nfield)
if (rp >= r_end) {
u_int pos;
size_t newsize;
+ char *nrecord;
pos = rp - record;
newsize = r_end - record + BFRAG;
- record = realloc(record, newsize);
- if (record == NULL) {
+ nrecord = realloc(record, newsize);
+ if (nrecord == NULL) {
+ if (record)
+ free(record);
errno = ENOMEM;
if (myfd)
(void)close(fd);
return (-2);
}
+ record = nrecord;
r_end = record + newsize;
rp = record + pos;
}
@@ -486,19 +490,23 @@ tc_exp: {
if (diff >= r_end - rp) {
u_int pos, tcpos, tcposend;
size_t newsize;
+ char *nrecord;
pos = rp - record;
newsize = r_end - record + diff + BFRAG;
tcpos = tcstart - record;
tcposend = tcend - record;
- record = realloc(record, newsize);
- if (record == NULL) {
+ nrecord = realloc(record, newsize);
+ if (nrecord == NULL) {
+ if (record)
+ free(record);
errno = ENOMEM;
if (myfd)
(void)close(fd);
free(icap);
return (-2);
}
+ record = nrecord;
r_end = record + newsize;
rp = record + pos;
tcstart = record + tcpos;
@@ -529,13 +537,18 @@ tc_exp: {
if (myfd)
(void)close(fd);
*len = rp - record - 1; /* don't count NUL */
- if (r_end > rp)
- if ((record =
+ if (r_end > rp) {
+ char *nrecord;
+
+ if ((nrecord =
realloc(record, (size_t)(rp - record))) == NULL) {
+ if (record)
+ free(record);
errno = ENOMEM;
return (-2);
}
-
+ record = nrecord;
+ }
*cap = record;
if (tc_not_resolved)
return (1);
@@ -871,9 +884,14 @@ cgetstr(buf, cap, str)
*/
if (m_room == 0) {
size_t size = mp - mem;
+ char *nmem;
- if ((mem = realloc(mem, size + SFRAG)) == NULL)
+ if ((nmem = realloc(mem, size + SFRAG)) == NULL) {
+ if (mem)
+ free(mem);
return (-2);
+ }
+ mem = nmem;
m_room = SFRAG;
mp = mem + size;
}
@@ -885,9 +903,16 @@ cgetstr(buf, cap, str)
/*
* Give back any extra memory and return value and success.
*/
- if (m_room != 0)
- if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL)
+ if (m_room != 0) {
+ char *nmem;
+
+ if ((nmem = realloc(mem, (size_t)(mp - mem))) == NULL) {
+ if (mem)
+ free(mem);
return (-2);
+ }
+ mem = nmem;
+ }
*str = mem;
return (len);
}
@@ -944,9 +969,14 @@ cgetustr(buf, cap, str)
*/
if (m_room == 0) {
size_t size = mp - mem;
+ char *nmem;
- if ((mem = realloc(mem, size + SFRAG)) == NULL)
+ if ((nmem = realloc(mem, size + SFRAG)) == NULL) {
+ if (mem)
+ free(mem);
return (-2);
+ }
+ mem = nmem;
m_room = SFRAG;
mp = mem + size;
}
@@ -958,9 +988,16 @@ cgetustr(buf, cap, str)
/*
* Give back any extra memory and return value and success.
*/
- if (m_room != 0)
- if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL)
+ if (m_room != 0) {
+ char *nmem;
+
+ if ((nmem = realloc(mem, (size_t)(mp - mem))) == NULL) {
+ if (mem)
+ free(mem);
return (-2);
+ }
+ mem = nmem;
+ }
*str = mem;
return (len);
}
diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c
index 7809e02f20e..5234bb8ff67 100644
--- a/lib/libc/gen/getcwd.c
+++ b/lib/libc/gen/getcwd.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getcwd.c,v 1.4 1997/07/09 00:28:20 millert Exp $";
+static char rcsid[] = "$OpenBSD: getcwd.c,v 1.5 1998/08/14 21:39:26 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -135,8 +135,11 @@ getcwd(pt, size)
* possible component name, plus a trailing NULL.
*/
if (bup + 3 + MAXNAMLEN + 1 >= eup) {
- if ((up = realloc(up, upsize *= 2)) == NULL)
+ char *nup;
+
+ if ((nup = realloc(up, upsize *= 2)) == NULL)
goto err;
+ up = nup;
bup = up;
eup = up + upsize;
}
@@ -189,6 +192,7 @@ getcwd(pt, size)
*/
if (bpt - pt <= dp->d_namlen + (first ? 1 : 2)) {
size_t len, off;
+ char *npt;
if (!ptsize) {
errno = ERANGE;
@@ -196,8 +200,9 @@ getcwd(pt, size)
}
off = bpt - pt;
len = ept - bpt;
- if ((pt = realloc(pt, ptsize *= 2)) == NULL)
+ if ((npt = realloc(pt, ptsize *= 2)) == NULL)
goto err;
+ pt = npt;
bpt = pt + off;
ept = pt + ptsize;
bcopy(bpt, ept - len, len);
@@ -225,7 +230,8 @@ notfound:
err:
if (ptsize)
free(pt);
- free(up);
+ if (up)
+ free(up);
if (dir)
(void)closedir(dir);
return (NULL);
diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c
index 1b6b6432ebb..dbcf4511a3c 100644
--- a/lib/libc/gen/getnetgrent.c
+++ b/lib/libc/gen/getnetgrent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getnetgrent.c,v 1.7 1997/10/10 23:07:30 deraadt Exp $ */
+/* $OpenBSD: getnetgrent.c,v 1.8 1998/08/14 21:39:28 deraadt Exp $ */
/*
* Copyright (c) 1994 Christos Zoulas
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: getnetgrent.c,v 1.7 1997/10/10 23:07:30 deraadt Exp $";
+static char *rcsid = "$OpenBSD: getnetgrent.c,v 1.8 1998/08/14 21:39:28 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -107,10 +107,17 @@ _ng_sl_add(sl, name)
char *name;
{
if (sl->sl_cur == sl->sl_max - 1) {
+ char **slstr;
+
sl->sl_max += 20;
- sl->sl_str = realloc(sl->sl_str, sl->sl_max * sizeof(char *));
- if (sl->sl_str == NULL)
+ slstr = realloc(sl->sl_str, sl->sl_max * sizeof(char *));
+ if (slstr == NULL) {
+ if (sl->sl_str)
+ free(sl->sl_str);
+ sl->sl_str = NULL;
_err(1, _ngoomem);
+ }
+ sl->sl_str = slstr;
}
sl->sl_str[sl->sl_cur++] = name;
}
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index 4144b356bbb..2b1b0d324e7 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -33,7 +33,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getpwent.c,v 1.13 1998/07/14 18:19:16 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: getpwent.c,v 1.14 1998/08/14 21:39:29 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -969,10 +969,17 @@ __hashpw(key)
return(0);
p = (char *)data.data;
if (data.size > max) {
+ char *nline;
+
max = data.size + 256;
- line = realloc(line, max);
- if (line == NULL)
+ nline = realloc(line, max);
+ if (nline == NULL) {
+ if (line)
+ free(line);
+ line = NULL;
return 0;
+ }
+ line = nline;
}
t = line;
diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c
index 08ec8125cc1..bb222ebf909 100644
--- a/lib/libc/gen/glob.c
+++ b/lib/libc/gen/glob.c
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
#else
-static char rcsid[] = "$OpenBSD: glob.c,v 1.7 1998/01/31 17:06:27 millert Exp $";
+static char rcsid[] = "$OpenBSD: glob.c,v 1.8 1998/08/14 21:39:30 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -658,8 +658,11 @@ globextend(path, pglob)
pathv = pglob->gl_pathv ?
realloc((char *)pglob->gl_pathv, newsize) :
malloc(newsize);
- if (pathv == NULL)
+ if (pathv == NULL) {
+ if (pglob->gl_pathv)
+ free(pglob->gl_pathv);
return(GLOB_NOSPACE);
+ }
if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
/* first time around -- clear initial gl_offs items */
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index 81aa0538c31..49948b40354 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: opendir.c,v 1.4 1997/07/09 00:28:23 millert Exp $";
+static char rcsid[] = "$OpenBSD: opendir.c,v 1.5 1998/08/14 21:39:31 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -132,10 +132,14 @@ __opendir2(name, flags)
* available to getdirentries
*/
if (space < DIRBLKSIZ) {
+ char *nbuf;
+
space += incr;
len += incr;
- buf = realloc(buf, len);
- if (buf == NULL) {
+ nbuf = realloc(buf, len);
+ if (nbuf == NULL) {
+ if (buf)
+ free(buf);
free(dirp);
close(fd);
return (NULL);
diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c
index c744b262ce4..d4c2281a438 100644
--- a/lib/libc/gen/scandir.c
+++ b/lib/libc/gen/scandir.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: scandir.c,v 1.3 1997/07/24 00:08:41 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: scandir.c,v 1.4 1998/08/14 21:39:32 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -106,13 +106,19 @@ scandir(dirname, namelist, select, dcomp)
* realloc the maximum size.
*/
if (++nitems >= arraysz) {
+ register struct dirent **nnames;
+
if (fstat(dirp->dd_fd, &stb) < 0)
return(-1); /* just might have grown */
arraysz = stb.st_size / 12;
- names = (struct dirent **)realloc((char *)names,
+ nnames = (struct dirent **)realloc((char *)names,
arraysz * sizeof(struct dirent *));
- if (names == NULL)
+ if (nnames == NULL) {
+ if (names)
+ free(names);
return(-1);
+ }
+ names = nnames;
}
names[nitems-1] = p;
}
diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c
index c13720e8cd3..72349eadfc6 100644
--- a/lib/libc/gen/setmode.c
+++ b/lib/libc/gen/setmode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: setmode.c,v 1.7 1997/07/25 20:30:04 mickey Exp $ */
+/* $OpenBSD: setmode.c,v 1.8 1998/08/14 21:39:33 deraadt Exp $ */
/* $NetBSD: setmode.c,v 1.15 1997/02/07 22:21:06 christos Exp $ */
/*
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94";
#else
-static char rcsid[] = "$OpenBSD: setmode.c,v 1.7 1997/07/25 20:30:04 mickey Exp $";
+static char rcsid[] = "$OpenBSD: setmode.c,v 1.8 1998/08/14 21:39:33 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -164,8 +164,12 @@ common: if (set->cmd2 & CMD2_CLR) {
register BITCMD *newset; \
setlen += SET_LEN_INCR; \
newset = realloc(saveset, sizeof(BITCMD) * setlen); \
- if (!saveset) \
+ if (!newset) { \
+ if (saveset) \
+ free(saveset); \
+ saveset = NULL; \
return (NULL); \
+ } \
set = newset + (set - saveset); \
saveset = newset; \
endset = newset + (setlen - 2); \
diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c
index 8e8cc319f62..0964bbf27e0 100644
--- a/lib/libc/regex/regcomp.c
+++ b/lib/libc/regex/regcomp.c
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94";
#else
-static char rcsid[] = "$OpenBSD: regcomp.c,v 1.5 1997/04/30 05:51:09 tholo Exp $";
+static char rcsid[] = "$OpenBSD: regcomp.c,v 1.6 1998/08/14 21:39:35 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -1248,16 +1248,21 @@ register cset *cs;
register char *cp;
{
register size_t oldend = cs->smultis;
+ void *np;
cs->smultis += strlen(cp) + 1;
if (cs->multis == NULL)
- cs->multis = malloc(cs->smultis);
+ np = malloc(cs->smultis);
else
- cs->multis = realloc(cs->multis, cs->smultis);
- if (cs->multis == NULL) {
+ np = realloc(cs->multis, cs->smultis);
+ if (np == NULL) {
+ if (cs->multis)
+ free(cs->multis);
+ cs->multis = NULL;
SETERROR(REG_ESPACE);
return;
}
+ cs->multis = np;
(void) strcpy(cs->multis + oldend - 1, cp);
cs->multis[cs->smultis - 1] = '\0';
diff --git a/lib/libc/rpc/get_myaddress.c b/lib/libc/rpc/get_myaddress.c
index 6768741bca7..929d32ff971 100644
--- a/lib/libc/rpc/get_myaddress.c
+++ b/lib/libc/rpc/get_myaddress.c
@@ -28,7 +28,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: get_myaddress.c,v 1.8 1997/09/22 05:11:07 millert Exp $";
+static char *rcsid = "$OpenBSD: get_myaddress.c,v 1.9 1998/08/14 21:39:36 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -61,7 +61,7 @@ get_myaddress(addr)
struct sockaddr_in *addr;
{
int s;
- char *inbuf = NULL;
+ char *inbuf = NULL, *ninbuf;
struct ifconf ifc;
struct ifreq ifreq, *ifr;
int len, inbuflen = 8192, slop;
@@ -72,11 +72,14 @@ get_myaddress(addr)
}
while (1) {
ifc.ifc_len = inbuflen;
- ifc.ifc_buf = inbuf = realloc(inbuf, inbuflen);
- if (inbuf == NULL) {
+ ninbuf = realloc(inbuf, inbuflen);
+ if (ninbuf == NULL) {
+ if (inbuf)
+ free(inbuf);
close(s);
return (-1);
}
+ ifc.ifc_buf = inbuf = ninbuf;
if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
(void) close(s);
free(inbuf);
diff --git a/lib/libc/rpc/pmap_rmt.c b/lib/libc/rpc/pmap_rmt.c
index befeadae989..e8f8750e233 100644
--- a/lib/libc/rpc/pmap_rmt.c
+++ b/lib/libc/rpc/pmap_rmt.c
@@ -28,7 +28,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: pmap_rmt.c,v 1.15 1997/07/09 03:05:05 deraadt Exp $";
+static char *rcsid = "$OpenBSD: pmap_rmt.c,v 1.16 1998/08/14 21:39:37 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -166,7 +166,7 @@ newgetbroadcastnets(addrsp, sock)
struct in_addr **addrsp;
int sock; /* any valid socket will do */
{
- char *inbuf = NULL;
+ char *inbuf = NULL, *ninbuf;
struct ifconf ifc;
struct ifreq ifreq, *ifr;
struct sockaddr_in *sin;
@@ -177,9 +177,13 @@ newgetbroadcastnets(addrsp, sock)
while (1) {
ifc.ifc_len = inbuflen;
- ifc.ifc_buf = inbuf = realloc(inbuf, inbuflen);
- if (inbuf == NULL)
+ ninbuf = realloc(inbuf, inbuflen);
+ if (ninbuf == NULL) {
+ if (inbuf)
+ free(inbuf);
return (0);
+ }
+ ifc.ifc_buf = inbuf = ninbuf;
if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
perror("broadcast: ioctl (get interface configuration)");
free(inbuf);
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));
diff --git a/lib/libc/time/ialloc.c b/lib/libc/time/ialloc.c
index 78ce8e6b54f..39bb4db7dce 100644
--- a/lib/libc/time/ialloc.c
+++ b/lib/libc/time/ialloc.c
@@ -1,6 +1,6 @@
#if defined(LIBC_SCCS) && !defined(lint) && !defined(NOID)
static char elsieid[] = "@(#)ialloc.c 8.29";
-static char rcsid[] = "$OpenBSD: ialloc.c,v 1.4 1998/01/18 23:24:52 millert Exp $";
+static char rcsid[] = "$OpenBSD: ialloc.c,v 1.5 1998/08/14 21:39:43 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
/*LINTLIBRARY*/
@@ -53,6 +53,8 @@ const char * const new;
if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
if (new != NULL)
(void) strcpy(result + oldsize, new);
+ else
+ free(old);
return result;
}
diff --git a/lib/libc/time/strftime.c b/lib/libc/time/strftime.c
index 892c31446cd..321d71fafc1 100644
--- a/lib/libc/time/strftime.c
+++ b/lib/libc/time/strftime.c
@@ -1,6 +1,6 @@
#if defined(LIBC_SCCS) && !defined(lint) && !defined(NOID)
static char elsieid[] = "@(#)strftime.c 7.57";
-static char *rcsid = "$OpenBSD: strftime.c,v 1.4 1998/07/06 19:00:38 millert Exp $";
+static char *rcsid = "$OpenBSD: strftime.c,v 1.5 1998/08/14 21:39:44 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include "private.h"
@@ -557,6 +557,7 @@ _loc P((void))
int fd;
int oldsun; /* "...ain't got nothin' to do..." */
char * lbuf;
+ char * nlbuf;
char * name;
char * p;
const char ** ap;
@@ -613,10 +614,15 @@ _loc P((void))
goto bad_locale;
bufsize = namesize + st.st_size;
locale_buf = NULL;
- lbuf = (lbuf == NULL || lbuf == locale_buf_C) ?
+ nlbuf = (lbuf == NULL || lbuf == locale_buf_C) ?
malloc(bufsize) : realloc(lbuf, bufsize);
- if (lbuf == NULL)
+ if (nlbuf == NULL) {
+ if (lbuf)
+ free(lbuf);
+ lbuf = NULL;
goto bad_locale;
+ }
+ lbuf = nlbuf;
(void) strcpy(lbuf, name);
p = lbuf + namesize;
plim = p + st.st_size;