Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/newfs - check return value of calloc() in mkfs()



details:   https://anonhg.NetBSD.org/src/rev/97123a3bc0d6
branches:  trunk
changeset: 513227:97123a3bc0d6
user:      lukem <lukem%NetBSD.org@localhost>
date:      Thu Jul 26 16:53:39 2001 +0000

description:
- check return value of calloc() in mkfs()
- in replacement malloc(), if sbrk(2) returns (void *)-1, convert to NULL
  before returning
- in replacement calloc(), check return value of malloc() before zeroing result

diffstat:

 sbin/newfs/mkfs.c |  16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diffs (58 lines):

diff -r b568e53c9149 -r 97123a3bc0d6 sbin/newfs/mkfs.c
--- a/sbin/newfs/mkfs.c Thu Jul 26 15:51:04 2001 +0000
+++ b/sbin/newfs/mkfs.c Thu Jul 26 16:53:39 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkfs.c,v 1.43 2001/07/26 03:46:57 lukem Exp $  */
+/*     $NetBSD: mkfs.c,v 1.44 2001/07/26 16:53:39 lukem Exp $  */
 
 /*
  * Copyright (c) 1980, 1989, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)mkfs.c     8.11 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: mkfs.c,v 1.43 2001/07/26 03:46:57 lukem Exp $");
+__RCSID("$NetBSD: mkfs.c,v 1.44 2001/07/26 16:53:39 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -536,6 +536,8 @@
        for (sblock.fs_csshift = 0; i > 1; i >>= 1)
                sblock.fs_csshift++;
        fscs = (struct csum *)calloc(1, sblock.fs_cssize);
+       if (fscs == NULL)
+               exit(39);
        sblock.fs_magic = FS_MAGIC;
        sblock.fs_rotdelay = rotdelay;
        sblock.fs_minfree = minfree;
@@ -1066,6 +1068,7 @@
 void *
 malloc(size_t size)
 {
+       void *p;
        char *base, *i;
        static u_long pgsz;
        struct rlimit rlp;
@@ -1087,8 +1090,11 @@
                size = memleft;
        memleft -= size;
        if (size == 0)
-               return (0);
-       return ((caddr_t)sbrk(size));
+               return (NULL);
+       p = sbrk(size);
+       if (p == (void *)-1)
+               p = NULL;
+       return (p);
 }
 
 /*
@@ -1116,6 +1122,8 @@
 
        size *= numelm;
        base = malloc(size);
+       if (base == NULL)
+               return (NULL);
        memset(base, 0, size);
        return (base);
 }



Home | Main Index | Thread Index | Old Index