Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/net Prevent NULL deref upon malloc failure.



details:   https://anonhg.NetBSD.org/src/rev/692ea8d1929a
branches:  trunk
changeset: 574416:692ea8d1929a
user:      lukem <lukem%NetBSD.org@localhost>
date:      Mon Feb 28 01:25:24 2005 +0000

description:
Prevent NULL deref upon malloc failure.

diffstat:

 lib/libc/net/hesiod.c |  17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diffs (46 lines):

diff -r 1ac06518f46a -r 692ea8d1929a lib/libc/net/hesiod.c
--- a/lib/libc/net/hesiod.c     Mon Feb 28 01:25:01 2005 +0000
+++ b/lib/libc/net/hesiod.c     Mon Feb 28 01:25:24 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hesiod.c,v 1.22 2004/05/23 16:54:13 christos Exp $     */
+/*     $NetBSD: hesiod.c,v 1.23 2005/02/28 01:25:24 lukem Exp $        */
 
 /* Copyright (c) 1996 by Internet Software Consortium.
  *
@@ -51,7 +51,7 @@
     "#Id: hesiod_p.h,v 1.1 1996/12/08 21:39:37 ghudson Exp #");
 __IDSTRING(rcsid_hescompat_c,
     "#Id: hescompat.c,v 1.1.2.1 1996/12/16 08:37:45 ghudson Exp #");
-__RCSID("$NetBSD: hesiod.c,v 1.22 2004/05/23 16:54:13 christos Exp $");
+__RCSID("$NetBSD: hesiod.c,v 1.23 2005/02/28 01:25:24 lukem Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -112,7 +112,7 @@
 
        _DIAGASSERT(context != NULL);
 
-       ctx = malloc(sizeof(struct hesiod_p));
+       ctx = calloc(1, sizeof(struct hesiod_p));
        if (ctx) {
                *context = ctx;
                /*
@@ -152,12 +152,13 @@
                errno = ENOMEM;
 
        serrno = errno;
-       if (ctx->lhs)
-               free(ctx->lhs);
-       if (ctx->rhs)
-               free(ctx->rhs);
-       if (ctx)
+       if (ctx) {
+               if (ctx->lhs)
+                       free(ctx->lhs);
+               if (ctx->rhs)
+                       free(ctx->rhs);
                free(ctx);
+       }
        errno = serrno;
        return -1;
 }



Home | Main Index | Thread Index | Old Index