Align CRYPTO_get_ex_new_index with the public API's calling convention Although we usually prefer not to use special -1 returns for errors, the public API does this across the board. Making the internal function different doesn't do much good. Change-Id: I6bfe8c9d989da81affeb5cb652de8d3edcbf5efa Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/66649 Reviewed-by: Bob Beck <bbe@google.com> Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/crypto/bio/bio.c b/crypto/bio/bio.c index 3206f6e..5456bd8 100644 --- a/crypto/bio/bio.c +++ b/crypto/bio/bio.c
@@ -714,12 +714,7 @@ CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index(&g_ex_data_class, argl, argp, free_func); } int BIO_set_ex_data(BIO *bio, int idx, void *data) {
diff --git a/crypto/dsa/dsa.c b/crypto/dsa/dsa.c index 4583dc6..37685d5 100644 --- a/crypto/dsa/dsa.c +++ b/crypto/dsa/dsa.c
@@ -934,12 +934,7 @@ int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index(&g_ex_data_class, argl, argp, free_func); } int DSA_set_ex_data(DSA *dsa, int idx, void *arg) {
diff --git a/crypto/ex_data.c b/crypto/ex_data.c index 7dc3272..8a88106 100644 --- a/crypto/ex_data.c +++ b/crypto/ex_data.c
@@ -132,11 +132,11 @@ CRYPTO_EX_DATA_FUNCS *next; }; -int CRYPTO_get_ex_new_index(CRYPTO_EX_DATA_CLASS *ex_data_class, int *out_index, - long argl, void *argp, CRYPTO_EX_free *free_func) { +int CRYPTO_get_ex_new_index(CRYPTO_EX_DATA_CLASS *ex_data_class, long argl, + void *argp, CRYPTO_EX_free *free_func) { CRYPTO_EX_DATA_FUNCS *funcs = OPENSSL_malloc(sizeof(CRYPTO_EX_DATA_FUNCS)); if (funcs == NULL) { - return 0; + return -1; } funcs->argl = argl; @@ -151,7 +151,7 @@ if (num_funcs > (size_t)(INT_MAX - ex_data_class->num_reserved)) { OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); CRYPTO_MUTEX_unlock_write(&ex_data_class->lock); - return 0; + return -1; } // Append |funcs| to the linked list. @@ -166,8 +166,7 @@ CRYPTO_atomic_store_u32(&ex_data_class->num_funcs, num_funcs + 1); CRYPTO_MUTEX_unlock_write(&ex_data_class->lock); - *out_index = (int)num_funcs + ex_data_class->num_reserved; - return 1; + return (int)num_funcs + ex_data_class->num_reserved; } int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int index, void *val) {
diff --git a/crypto/fipsmodule/ec/ec_key.c b/crypto/fipsmodule/ec/ec_key.c index c75d90b..834cc78 100644 --- a/crypto/fipsmodule/ec/ec_key.c +++ b/crypto/fipsmodule/ec/ec_key.c
@@ -534,12 +534,8 @@ int EC_KEY_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(g_ec_ex_data_class_bss_get(), &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index(g_ec_ex_data_class_bss_get(), argl, argp, + free_func); } int EC_KEY_set_ex_data(EC_KEY *d, int idx, void *arg) {
diff --git a/crypto/fipsmodule/rsa/rsa.c b/crypto/fipsmodule/rsa/rsa.c index 8babba1..b80bda9 100644 --- a/crypto/fipsmodule/rsa/rsa.c +++ b/crypto/fipsmodule/rsa/rsa.c
@@ -439,12 +439,8 @@ int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(g_rsa_ex_data_class_bss_get(), &index, argl, - argp, free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index(g_rsa_ex_data_class_bss_get(), argl, argp, + free_func); } int RSA_set_ex_data(RSA *rsa, int idx, void *arg) {
diff --git a/crypto/internal.h b/crypto/internal.h index b5e27f5..8e7fc86 100644 --- a/crypto/internal.h +++ b/crypto/internal.h
@@ -905,13 +905,11 @@ #define CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA \ {CRYPTO_MUTEX_INIT, NULL, NULL, 0, 1} -// CRYPTO_get_ex_new_index allocates a new index for |ex_data_class| and writes -// it to |*out_index|. Each class of object should provide a wrapper function -// that uses the correct |CRYPTO_EX_DATA_CLASS|. It returns one on success and -// zero otherwise. +// CRYPTO_get_ex_new_index allocates a new index for |ex_data_class|. Each class +// of object should provide a wrapper function that uses the correct +// |CRYPTO_EX_DATA_CLASS|. It returns the new index on success and -1 on error. OPENSSL_EXPORT int CRYPTO_get_ex_new_index(CRYPTO_EX_DATA_CLASS *ex_data_class, - int *out_index, long argl, - void *argp, + long argl, void *argp, CRYPTO_EX_free *free_func); // CRYPTO_set_ex_data sets an extra data pointer on a given object. Each class
diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c index 81e413e..4576247 100644 --- a/crypto/x509/x509_vfy.c +++ b/crypto/x509/x509_vfy.c
@@ -1409,14 +1409,7 @@ CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - // This function is (usually) called only once, by - // SSL_get_ex_data_X509_STORE_CTX_idx (ssl/ssl_cert.c). - int index; - if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index(&g_ex_data_class, argl, argp, free_func); } int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, void *data) {
diff --git a/crypto/x509/x_x509.c b/crypto/x509/x_x509.c index 1d3ebf6..3434352 100644 --- a/crypto/x509/x_x509.c +++ b/crypto/x509/x_x509.c
@@ -380,12 +380,7 @@ int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index(&g_ex_data_class, argl, argp, free_func); } int X509_set_ex_data(X509 *r, int idx, void *arg) {
diff --git a/ssl/ssl_lib.cc b/ssl/ssl_lib.cc index f95cd5d..55f426c 100644 --- a/ssl/ssl_lib.cc +++ b/ssl/ssl_lib.cc
@@ -2671,12 +2671,7 @@ int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(&g_ex_data_class_ssl, &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index(&g_ex_data_class_ssl, argl, argp, free_func); } int SSL_set_ex_data(SSL *ssl, int idx, void *data) { @@ -2690,12 +2685,8 @@ int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(&g_ex_data_class_ssl_ctx, &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index(&g_ex_data_class_ssl_ctx, argl, argp, + free_func); } int SSL_CTX_set_ex_data(SSL_CTX *ctx, int idx, void *data) {
diff --git a/ssl/ssl_session.cc b/ssl/ssl_session.cc index 5275b69..7f9b99f 100644 --- a/ssl/ssl_session.cc +++ b/ssl/ssl_session.cc
@@ -1203,12 +1203,7 @@ CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index(&g_ex_data_class, argl, argp, free_func); } int SSL_SESSION_set_ex_data(SSL_SESSION *session, int idx, void *arg) {