Use calloc() for X509_CRL_METHOD_new() instead of malloc().
authorjsing <jsing@openbsd.org>
Fri, 3 Dec 2021 17:07:53 +0000 (17:07 +0000)
committerjsing <jsing@openbsd.org>
Fri, 3 Dec 2021 17:07:53 +0000 (17:07 +0000)
This ensures that if any members are added to this struct, they will be
initialised.

ok schwarze@ tb@

lib/libcrypto/asn1/x_crl.c

index bfc01a2..8cea9e0 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: x_crl.c,v 1.35 2021/11/01 20:53:08 tb Exp $ */
+/* $OpenBSD: x_crl.c,v 1.36 2021/12/03 17:07:53 jsing Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -660,14 +660,15 @@ X509_CRL_METHOD_new(int (*crl_init)(X509_CRL *crl),
 {
        X509_CRL_METHOD *m;
 
-       m = malloc(sizeof(X509_CRL_METHOD));
-       if (!m)
+       if ((m = calloc(1, sizeof(X509_CRL_METHOD))) == NULL)
                return NULL;
+
        m->crl_init = crl_init;
        m->crl_free = crl_free;
        m->crl_lookup = crl_lookup;
        m->crl_verify = crl_verify;
        m->flags = X509_CRL_METHOD_DYNAMIC;
+
        return m;
 }