Commit c5ebfcab authored by FdaSilvaYY's avatar FdaSilvaYY Committed by Matt Caswell
Browse files

Unify <TYPE>_up_ref methods signature and behaviour.



Add a status return value instead of void.
Add some sanity checks on reference counter value.
Update the docs.

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
Reviewed-by: default avatarMatt Caswell <matt@openssl.org>
parent 592b6fb4
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -2,7 +2,15 @@
 OpenSSL CHANGES
 _______________
 Changes between 1.0.2g and 1.1.0  [xx XXX xxxx]
 Changes between 1.0.2h and 1.1.0  [xx XXX 2016]
  *) Unify TYPE_up_ref(obj) methods signature.
     SSL_CTX_up_ref(), SSL_up_ref(), X509_up_ref(), EVP_PKEY_up_ref(),
     X509_CRL_up_ref(), X509_OBJECT_up_ref_count() methods are now returning an
     int (instead of void) like all others TYPE_up_ref() methods.
     So now these methods also check the return value of CRYPTO_atomic_add(),
     and the validity of object reference counter.
     [fdasilvayy@gmail.com]
  *) With Windows Visual Studio builds, the .pdb files are installed
     alongside the installed libraries and executables.  For a static
+8 −2
Original line number Diff line number Diff line
@@ -196,10 +196,16 @@ EVP_PKEY *EVP_PKEY_new(void)
    return ret;
}

void EVP_PKEY_up_ref(EVP_PKEY *pkey)
int EVP_PKEY_up_ref(EVP_PKEY *pkey)
{
    int i;
    CRYPTO_atomic_add(&pkey->references, 1, &i, pkey->lock);

    if (CRYPTO_atomic_add(&pkey->references, 1, &i, pkey->lock) <= 0)
        return 0;

    REF_PRINT_COUNT("EVP_PKEY", pkey);
    REF_ASSERT_ISNT(i < 2);
    return ((i > 1) ? 1 : 0);
}

/*
+4 −5
Original line number Diff line number Diff line
@@ -417,18 +417,17 @@ int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
    return ret;
}

void X509_OBJECT_up_ref_count(X509_OBJECT *a)
int X509_OBJECT_up_ref_count(X509_OBJECT *a)
{
    switch (a->type) {
    default:
        break;
    case X509_LU_X509:
        X509_up_ref(a->data.x509);
        break;
        return X509_up_ref(a->data.x509);
    case X509_LU_CRL:
        X509_CRL_up_ref(a->data.crl);
        break;
        return X509_CRL_up_ref(a->data.crl);
    }
    return 1;
}

X509 *X509_OBJECT_get0_X509(X509_OBJECT *a)
+8 −2
Original line number Diff line number Diff line
@@ -146,10 +146,16 @@ int X509_set_pubkey(X509 *x, EVP_PKEY *pkey)
    return (X509_PUBKEY_set(&(x->cert_info.key), pkey));
}

void X509_up_ref(X509 *x)
int X509_up_ref(X509 *x)
{
    int i;
    CRYPTO_atomic_add(&x->references, 1, &i, x->lock);

    if (CRYPTO_atomic_add(&x->references, 1, &i, x->lock) <= 0)
        return 0;

    REF_PRINT_COUNT("X509", x);
    REF_ASSERT_ISNT(i < 2);
    return ((i > 1) ? 1 : 0);
}

long X509_get_version(X509 *x)
+8 −2
Original line number Diff line number Diff line
@@ -132,10 +132,16 @@ int X509_CRL_sort(X509_CRL *c)
    return 1;
}

void X509_CRL_up_ref(X509_CRL *crl)
int X509_CRL_up_ref(X509_CRL *crl)
{
    int i;
    CRYPTO_atomic_add(&crl->references, 1, &i, crl->lock);

    if (CRYPTO_atomic_add(&crl->references, 1, &i, crl->lock) <= 0)
        return 0;

    REF_PRINT_COUNT("X509_CRL", crl);
    REF_ASSERT_ISNT(i < 2);
    return ((i > 1) ? 1 : 0);
}

long X509_CRL_get_version(X509_CRL *crl)
Loading