Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/ndbootd ndbootd(8): Rework allocation macros to add...



details:   https://anonhg.NetBSD.org/src/rev/f6af24b72fc7
branches:  trunk
changeset: 990553:f6af24b72fc7
user:      nia <nia%NetBSD.org@localhost>
date:      Sat Oct 30 10:44:25 2021 +0000

description:
ndbootd(8): Rework allocation macros to add integer overflow checking.

diffstat:

 usr.sbin/ndbootd/ndbootd.c |  27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)

diffs (73 lines):

diff -r f42f0891b01c -r f6af24b72fc7 usr.sbin/ndbootd/ndbootd.c
--- a/usr.sbin/ndbootd/ndbootd.c        Sat Oct 30 10:34:18 2021 +0000
+++ b/usr.sbin/ndbootd/ndbootd.c        Sat Oct 30 10:44:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ndbootd.c,v 1.12 2007/04/08 09:43:51 scw Exp $ */
+/*     $NetBSD: ndbootd.c,v 1.13 2021/10/30 10:44:25 nia Exp $ */
 
 /* ndbootd.c - the Sun Network Disk (nd) daemon: */
 
@@ -81,7 +81,7 @@
 #if 0
 static const char _ndbootd_c_rcsid[] = "<<Id: ndbootd.c,v 1.9 2001/06/13 21:19:11 fredette Exp >>";
 #else
-__RCSID("$NetBSD: ndbootd.c,v 1.12 2007/04/08 09:43:51 scw Exp $");
+__RCSID("$NetBSD: ndbootd.c,v 1.13 2021/10/30 10:44:25 nia Exp $");
 #endif
 
 /* includes: */
@@ -128,8 +128,8 @@
 #endif                         /* !HAVE_SOCKADDR_SA_LEN */
 
 /* prototypes: */
-void *ndbootd_malloc _NDBOOTD_P((size_t));
-void *ndbootd_malloc0 _NDBOOTD_P((size_t));
+void *ndbootd_malloc _NDBOOTD_P((size_t, size_t));
+void *ndbootd_calloc _NDBOOTD_P((size_t, size_t));
 void *ndbootd_memdup _NDBOOTD_P((void *, size_t));
 
 /* globals: */
@@ -140,33 +140,34 @@
 
 /* allocators: */
 void *
-ndbootd_malloc(size_t size)
+ndbootd_malloc(size_t number, size_t size)
 {
-       void *buffer;
-       if ((buffer = malloc(size)) == NULL) {
+       void *buffer = NULL;
+       if (reallocarr(&buffer, number, size) != 0) {
                abort();
        }
        return (buffer);
 }
 void *
-ndbootd_malloc0(size_t size)
+ndbootd_calloc(size_t number, size_t size)
 {
        void *buffer;
-       buffer = ndbootd_malloc(size);
-       memset(buffer, 0, size);
+       if ((buffer = calloc(number, size)) == NULL) {
+               abort();
+       }
        return (buffer);
 }
 void *
 ndbootd_memdup(void *buffer0, size_t size)
 {
        void *buffer1;
-       buffer1 = ndbootd_malloc(size);
+       buffer1 = ndbootd_malloc(1, size);
        memcpy(buffer1, buffer0, size);
        return (buffer1);
 }
 #define ndbootd_free free
-#define ndbootd_new(t, c) ((t *) ndbootd_malloc(sizeof(t) * (c)))
-#define ndbootd_new0(t, c) ((t *) ndbootd_malloc0(sizeof(t) * (c)))
+#define ndbootd_new(t, c) ((t *) ndbootd_malloc(c, sizeof(t)))
+#define ndbootd_new0(t, c) ((t *) ndbootd_calloc(c, sizeof(t)))
 #define ndbootd_dup(t, b, c) ((t *) ndbootd_memdup(b, c))
 
 /* this calculates an IP packet header checksum: */



Home | Main Index | Thread Index | Old Index