Commit b51bce94 authored by Rich Salz's avatar Rich Salz Committed by Rich Salz
Browse files

Add and use OPENSSL_zalloc



There are many places (nearly 50) where we malloc and then memset.
Add an OPENSSL_zalloc routine to encapsulate that.
(Missed one conversion; thanks Richard)
Also fixes GH328

Reviewed-by: default avatarRichard Levitte <levitte@openssl.org>
parent 66e87a9f
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -283,12 +283,11 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(EVP_PKEY *pkey)
EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,
                                        const char *pem_str, const char *info)
{
    EVP_PKEY_ASN1_METHOD *ameth;
    ameth = OPENSSL_malloc(sizeof(*ameth));
    EVP_PKEY_ASN1_METHOD *ameth = OPENSSL_zalloc(sizeof(*ameth));

    if (!ameth)
        return NULL;

    memset(ameth, 0, sizeof(*ameth));
    ameth->pkey_id = id;
    ameth->pkey_base_id = id;
    ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC;
+2 −4
Original line number Diff line number Diff line
@@ -135,10 +135,9 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
                return 1;
            }
        }
        *pval = OPENSSL_malloc(it->size);
        *pval = OPENSSL_zalloc(it->size);
        if (!*pval)
            goto memerr;
        memset(*pval, 0, it->size);
        asn1_set_choice_selector(pval, -1, it);
        if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
            goto auxerr;
@@ -158,10 +157,9 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
                return 1;
            }
        }
        *pval = OPENSSL_malloc(it->size);
        *pval = OPENSSL_zalloc(it->size);
        if (!*pval)
            goto memerr;
        memset(*pval, 0, it->size);
        asn1_do_lock(pval, 0, it);
        asn1_enc_init(pval, it);
        for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
+1 −2
Original line number Diff line number Diff line
@@ -66,10 +66,9 @@ X509_PKEY *X509_PKEY_new(void)
{
    X509_PKEY *ret = NULL;

    ret = OPENSSL_malloc(sizeof(*ret));
    ret = OPENSSL_zalloc(sizeof(*ret));
    if (!ret)
        goto err;
    memset(ret, 0, sizeof(*ret));

    ret->version = 0;
    ret->enc_algor = X509_ALGOR_new();
+1 −3
Original line number Diff line number Diff line
@@ -137,10 +137,8 @@ static BIO_ACCEPT *BIO_ACCEPT_new(void)
{
    BIO_ACCEPT *ret;

    if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
        return (NULL);

    memset(ret, 0, sizeof(*ret));
    ret->accept_sock = INVALID_SOCKET;
    ret->bind_mode = BIO_BIND_NORMAL;
    return (ret);
+1 −8
Original line number Diff line number Diff line
@@ -286,19 +286,12 @@ BIO_CONNECT *BIO_CONNECT_new(void)
{
    BIO_CONNECT *ret;

    if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
        return (NULL);
    ret->state = BIO_CONN_S_BEFORE;
    ret->param_hostname = NULL;
    ret->param_port = NULL;
    ret->info_callback = NULL;
    ret->nbio = 0;
    ret->ip[0] = 0;
    ret->ip[1] = 0;
    ret->ip[2] = 0;
    ret->ip[3] = 0;
    ret->port = 0;
    memset(&ret->them, 0, sizeof(ret->them));
    return (ret);
}

Loading