summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2002-07-11 21:23:30 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2002-07-11 21:23:30 +0000
commit364af8a6959831d6abf08c4be270fc8fa36a3558 (patch)
tree209a46d0ba7282ded089f4ffe251892d7784dc03
parent442fb3a9589843c4a2efce416f37fb12e8dddb5b (diff)
malloc() failure tests; rimshot@pandora.be
-rw-r--r--sbin/dumplfs/dumplfs.c6
-rw-r--r--sbin/fdisk/disk.c6
-rw-r--r--sbin/isakmpd/pf_key_v2.c4
-rw-r--r--sbin/modload/modload.c6
-rw-r--r--sbin/mount_portal/mount_portal.c6
-rw-r--r--sbin/mountd/mountd.c8
-rw-r--r--sbin/ncheck_ffs/ncheck_ffs.c8
7 files changed, 33 insertions, 11 deletions
diff --git a/sbin/dumplfs/dumplfs.c b/sbin/dumplfs/dumplfs.c
index 4c5653a3a2a..fe0f538c810 100644
--- a/sbin/dumplfs/dumplfs.c
+++ b/sbin/dumplfs/dumplfs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dumplfs.c,v 1.7 2002/06/09 08:13:05 todd Exp $ */
+/* $OpenBSD: dumplfs.c,v 1.8 2002/07/11 21:23:28 deraadt Exp $ */
/* $NetBSD: dumplfs.c,v 1.7 1995/12/14 22:36:34 thorpej Exp $ */
/*-
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)dumplfs.c 8.1 (Berkeley) 6/5/93";
#else
-static char rcsid[] = "$OpenBSD: dumplfs.c,v 1.7 2002/06/09 08:13:05 todd Exp $";
+static char rcsid[] = "$OpenBSD: dumplfs.c,v 1.8 2002/07/11 21:23:28 deraadt Exp $";
#endif
#endif /* not lint */
@@ -420,6 +420,8 @@ dump_sum(fd, lfsp, sp, segnum, addr)
dp = (daddr_t *)sp;
dp += LFS_SUMMARY_SIZE / sizeof(daddr_t);
inop = malloc(1 << lfsp->lfs_bshift);
+ if (inop == NULL)
+ err(1, "malloc");
printf(" Inode addresses:");
for (dp--, i = 0; i < sp->ss_ninos; dp--) {
printf("\t0x%X {", *dp);
diff --git a/sbin/fdisk/disk.c b/sbin/fdisk/disk.c
index 7d48cd711e9..86fce510a27 100644
--- a/sbin/fdisk/disk.c
+++ b/sbin/fdisk/disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.c,v 1.15 2002/04/25 22:13:13 espie Exp $ */
+/* $OpenBSD: disk.c,v 1.16 2002/07/11 21:23:28 deraadt Exp $ */
/*
* Copyright (c) 1997, 2001 Tobias Weingartner
@@ -92,6 +92,8 @@ DISK_getlabelmetrics(name)
/* Get label metrics */
if ((fd = DISK_open(name, O_RDONLY)) != -1) {
lm = malloc(sizeof(DISK_metrics));
+ if (lm == NULL)
+ err(1, "malloc");
if (ioctl(fd, DIOCGDINFO, &dl) == -1) {
warn("DIOCGDINFO");
@@ -154,6 +156,8 @@ DISK_getbiosmetrics(name)
}
bm = malloc(sizeof(di));
+ if (bm == NULL)
+ err(1, "malloc");
bm->cylinders = di.bios_cylinders;
bm->heads = di.bios_heads;
bm->sectors = di.bios_sectors;
diff --git a/sbin/isakmpd/pf_key_v2.c b/sbin/isakmpd/pf_key_v2.c
index 4f29517811a..efe68c8e95c 100644
--- a/sbin/isakmpd/pf_key_v2.c
+++ b/sbin/isakmpd/pf_key_v2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_key_v2.c,v 1.112 2002/07/05 11:08:13 ho Exp $ */
+/* $OpenBSD: pf_key_v2.c,v 1.113 2002/07/11 21:23:28 deraadt Exp $ */
/* $EOM: pf_key_v2.c,v 1.79 2000/12/12 00:33:19 niklas Exp $ */
/*
@@ -163,7 +163,7 @@ pf_key_v2_register_sa_seq (u_int8_t *spi, size_t sz, u_int8_t proto,
if (!node->spi)
goto cleanup;
node->dst = malloc (sysdep_sa_len (dst));
- if (!node->spi)
+ if (!node->dst)
goto cleanup;
memcpy (node->dst, dst, sysdep_sa_len (dst));
node->dstlen = sysdep_sa_len (dst);
diff --git a/sbin/modload/modload.c b/sbin/modload/modload.c
index 9f1759e912f..df30f7a485e 100644
--- a/sbin/modload/modload.c
+++ b/sbin/modload/modload.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: modload.c,v 1.34 2002/06/09 08:13:07 todd Exp $ */
+/* $OpenBSD: modload.c,v 1.35 2002/07/11 21:23:28 deraadt Exp $ */
/* $NetBSD: modload.c,v 1.30 2001/11/08 15:33:15 christos Exp $ */
/*
@@ -160,6 +160,8 @@ verify_entry(const char *entry, char *filename)
memset(names, 0, sizeof(names));
s = malloc(strlen(entry) + 2);
+ if (s == NULL)
+ err(1, "malloc");
sprintf(s, "_%s", entry); /* safe */
#ifdef _AOUT_INCLUDE_
names[0].n_un.n_name = s;
@@ -323,6 +325,8 @@ main(int argc, char **argv)
else
p = modout;
entry = malloc(strlen(p) + strlen(DFLT_ENTRYEXT) + 1);
+ if (entry == NULL)
+ err(1, "malloc");
sprintf(entry, "%s%s", p, DFLT_ENTRYEXT); /* safe */
if (verify_entry(entry, modobj))
errx(1, "entry point _%s not found in %s",
diff --git a/sbin/mount_portal/mount_portal.c b/sbin/mount_portal/mount_portal.c
index 38dd40697cd..5f14c5740e7 100644
--- a/sbin/mount_portal/mount_portal.c
+++ b/sbin/mount_portal/mount_portal.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mount_portal.c,v 1.20 2002/05/26 09:24:35 deraadt Exp $ */
+/* $OpenBSD: mount_portal.c,v 1.21 2002/07/11 21:23:29 deraadt Exp $ */
/* $NetBSD: mount_portal.c,v 1.8 1996/04/13 01:31:54 jtc Exp $ */
/*
@@ -47,7 +47,7 @@ char copyright[] =
#if 0
static char sccsid[] = "@(#)mount_portal.c 8.6 (Berkeley) 4/26/95";
#else
-static char rcsid[] = "$OpenBSD: mount_portal.c,v 1.20 2002/05/26 09:24:35 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: mount_portal.c,v 1.21 2002/07/11 21:23:29 deraadt Exp $";
#endif
#endif /* not lint */
@@ -220,6 +220,8 @@ main(argc, argv)
fdssize = howmany(so+1, NFDBITS) * sizeof(fd_mask);
fdsp = (fd_set *)malloc(fdssize);
+ if (fdsp == NULL)
+ err(1, "malloc");
/*
* Just loop waiting for new connections and activating them
diff --git a/sbin/mountd/mountd.c b/sbin/mountd/mountd.c
index 7135e436eb0..f048fec975c 100644
--- a/sbin/mountd/mountd.c
+++ b/sbin/mountd/mountd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mountd.c,v 1.49 2002/06/29 23:19:49 deraadt Exp $ */
+/* $OpenBSD: mountd.c,v 1.50 2002/07/11 21:23:29 deraadt Exp $ */
/* $NetBSD: mountd.c,v 1.31 1996/02/18 11:57:53 fvdl Exp $ */
/*
@@ -1092,6 +1092,8 @@ add_expdir(struct dirlist **dpp, char *cp, int len)
struct dirlist *dp;
dp = (struct dirlist *)malloc(sizeof (struct dirlist) + len);
+ if (dp == NULL)
+ out_of_mem();
dp->dp_left = *dpp;
dp->dp_right = NULL;
dp->dp_flag = 0;
@@ -1866,6 +1868,8 @@ get_mountlist(void)
if (host == NULL || dirp == NULL)
continue;
mlp = (struct mountlist *)malloc(sizeof (*mlp));
+ if (mlp == NULL)
+ out_of_mem();
strlcpy(mlp->ml_host, host, sizeof(mlp->ml_host));
strlcpy(mlp->ml_dirp, dirp, sizeof(mlp->ml_dirp));
mlp->ml_next = NULL;
@@ -1927,6 +1931,8 @@ add_mlist(char *hostp, char *dirp)
mlp = mlp->ml_next;
}
mlp = (struct mountlist *)malloc(sizeof (*mlp));
+ if (mlp == NULL)
+ out_of_mem();
strlcpy(mlp->ml_host, hostp, sizeof(mlp->ml_host));
strlcpy(mlp->ml_dirp, dirp, sizeof(mlp->ml_dirp));
mlp->ml_next = NULL;
diff --git a/sbin/ncheck_ffs/ncheck_ffs.c b/sbin/ncheck_ffs/ncheck_ffs.c
index f814ce68d0e..361936762ea 100644
--- a/sbin/ncheck_ffs/ncheck_ffs.c
+++ b/sbin/ncheck_ffs/ncheck_ffs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ncheck_ffs.c,v 1.12 2002/07/03 22:32:33 deraadt Exp $ */
+/* $OpenBSD: ncheck_ffs.c,v 1.13 2002/07/11 21:23:29 deraadt Exp $ */
/*-
* Copyright (c) 1995, 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
@@ -31,7 +31,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: ncheck_ffs.c,v 1.12 2002/07/03 22:32:33 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: ncheck_ffs.c,v 1.13 2002/07/11 21:23:29 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -128,6 +128,8 @@ cacheino(ino_t ino, struct dinode *ip)
icache = realloc(icache, (nicache + 1) * sizeof(struct icache_s));
else
icache = malloc(sizeof(struct icache_s));
+ if (icache == NULL)
+ errx(1, "malloc");
icache[nicache].ino = ino;
icache[nicache++].di = *ip;
}
@@ -383,6 +385,8 @@ searchdir(ino_t ino, daddr_t blkno, long size, long filesize,
}
len = strlen(path) + strlen(dp->d_name) + 2;
npath = malloc(len);
+ if (npath == NULL)
+ errx(1, "malloc");
snprintf(npath, len, "%s/%s", path, dp->d_name);
scanonedir(dp->d_ino, npath);
free(npath);