From: FdaSilvaYY Date: Fri, 10 Jun 2016 21:28:44 +0000 (+0200) Subject: Discard BIO_set(BIO* bio) method X-Git-Tag: OpenSSL_1_1_0-pre6~79 X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff_plain;h=9d7bfb14dd22c372d6583c20583cbf9aea4cc033 Discard BIO_set(BIO* bio) method Simplify BIO init using OPENSSL_zalloc(). Reviewed-by: Matt Caswell Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/1261) --- diff --git a/crypto/bio/bio_err.c b/crypto/bio/bio_err.c index d032dedbb7..8f88cb92e5 100644 --- a/crypto/bio/bio_err.c +++ b/crypto/bio/bio_err.c @@ -43,7 +43,6 @@ static ERR_STRING_DATA BIO_str_functs[] = { {ERR_FUNC(BIO_F_BIO_PARSE_HOSTSERV), "BIO_parse_hostserv"}, {ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"}, {ERR_FUNC(BIO_F_BIO_READ), "BIO_read"}, - {ERR_FUNC(BIO_F_BIO_SET), "BIO_set"}, {ERR_FUNC(BIO_F_BIO_SOCKET), "BIO_socket"}, {ERR_FUNC(BIO_F_BIO_SOCKET_NBIO), "BIO_socket_nbio"}, {ERR_FUNC(BIO_F_BIO_SOCK_INFO), "BIO_sock_info"}, diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index 0b111c663c..98f3707ea5 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -12,58 +12,42 @@ #include #include "bio_lcl.h" #include "internal/cryptlib.h" -#include BIO *BIO_new(const BIO_METHOD *method) { - BIO *ret = OPENSSL_malloc(sizeof(*ret)); + BIO *bio = OPENSSL_zalloc(sizeof(*bio)); - if (ret == NULL) { + if (bio == NULL) { BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE); return (NULL); } - if (!BIO_set(ret, method)) { - OPENSSL_free(ret); - ret = NULL; - } - return (ret); -} -int BIO_set(BIO *bio, const BIO_METHOD *method) -{ bio->method = method; - bio->callback = NULL; - bio->cb_arg = NULL; - bio->init = 0; bio->shutdown = 1; - bio->flags = 0; - bio->retry_reason = 0; - bio->num = 0; - bio->ptr = NULL; - bio->prev_bio = NULL; - bio->next_bio = NULL; bio->references = 1; - bio->num_read = 0L; - bio->num_write = 0L; + if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data)) - return 0; + goto err; bio->lock = CRYPTO_THREAD_lock_new(); if (bio->lock == NULL) { - BIOerr(BIO_F_BIO_SET, ERR_R_MALLOC_FAILURE); + BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE); CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); - return 0; + goto err; } - if (method->create != NULL) { - if (!method->create(bio)) { - CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); - CRYPTO_THREAD_lock_free(bio->lock); - return 0; - } + if (method->create != NULL && !method->create(bio)) { + BIOerr(BIO_F_BIO_NEW, ERR_R_INIT_FAIL); + CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); + CRYPTO_THREAD_lock_free(bio->lock); + goto err; } - return 1; + return bio; + +err: + OPENSSL_free(bio); + return NULL; } int BIO_free(BIO *a) diff --git a/doc/crypto/BIO_meth_new.pod b/doc/crypto/BIO_meth_new.pod index 2c2db6f578..65e48cb24f 100644 --- a/doc/crypto/BIO_meth_new.pod +++ b/doc/crypto/BIO_meth_new.pod @@ -88,7 +88,7 @@ BIO_ctrl(). BIO_meth_get_create() and BIO_meth_set_create() get and set the function used for creating a new instance of the BIO respectively. This function will be -called in response to the application calling BIO_new() or BIO_set() and passing +called in response to the application calling BIO_new() and passing in a pointer to the current BIO_METHOD. The BIO_new() function will allocate the memory for the new BIO, and a pointer to this newly allocated structure will be passed as a parameter to the function. diff --git a/doc/crypto/BIO_new.pod b/doc/crypto/BIO_new.pod index 226f13feef..006cf5925c 100644 --- a/doc/crypto/BIO_new.pod +++ b/doc/crypto/BIO_new.pod @@ -2,7 +2,8 @@ =head1 NAME -BIO_new, BIO_set, BIO_up_ref, BIO_free, BIO_vfree, BIO_free_all - BIO allocation and freeing functions +BIO_new, BIO_up_ref, BIO_free, BIO_vfree, BIO_free_all, +BIO_set - BIO allocation and freeing functions =head1 SYNOPSIS @@ -19,8 +20,6 @@ BIO_new, BIO_set, BIO_up_ref, BIO_free, BIO_vfree, BIO_free_all - BIO allocation The BIO_new() function returns a new BIO using method B. -BIO_set() sets the method of an already existing BIO. - BIO_up_ref() increments the reference count associated with the BIO object. BIO_free() frees up a single BIO, BIO_vfree() also frees up a single BIO @@ -51,6 +50,10 @@ in a memory leak. Calling BIO_free_all() on a single BIO has the same effect as calling BIO_free() on it other than the discarded return value. +=head1 HISTORY + +BIO_set() was removed in OpenSSL 1.1.0 as BIO type is now opaque. + =head1 EXAMPLE Create a memory BIO: diff --git a/include/openssl/bio.h b/include/openssl/bio.h index ed50139ed4..f847348d5a 100644 --- a/include/openssl/bio.h +++ b/include/openssl/bio.h @@ -533,7 +533,6 @@ BIO *BIO_new_file(const char *filename, const char *mode); BIO *BIO_new_fp(FILE *stream, int close_flag); # endif BIO *BIO_new(const BIO_METHOD *type); -int BIO_set(BIO *a, const BIO_METHOD *type); int BIO_free(BIO *a); void BIO_set_data(BIO *a, void *ptr); void *BIO_get_data(BIO *a); @@ -792,7 +791,6 @@ int ERR_load_BIO_strings(void); # define BIO_F_BIO_PARSE_HOSTSERV 136 # define BIO_F_BIO_PUTS 110 # define BIO_F_BIO_READ 111 -# define BIO_F_BIO_SET 143 # define BIO_F_BIO_SOCKET 140 # define BIO_F_BIO_SOCKET_NBIO 142 # define BIO_F_BIO_SOCK_INFO 141 diff --git a/util/libcrypto.num b/util/libcrypto.num index 1fb7cf3114..22f76f4243 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -2805,7 +2805,7 @@ OPENSSL_init 2761 1_1_0 EXIST::FUNCTION: TS_RESP_get_tst_info 2762 1_1_0 EXIST::FUNCTION:TS X509_VERIFY_PARAM_get_depth 2763 1_1_0 EXIST::FUNCTION: EVP_SealFinal 2764 1_1_0 EXIST::FUNCTION:RSA -BIO_set 2765 1_1_0 EXIST::FUNCTION: +BIO_set 2765 1_1_0 NOEXIST::FUNCTION: CONF_imodule_set_flags 2766 1_1_0 EXIST::FUNCTION: i2d_ASN1_SET_ANY 2767 1_1_0 EXIST::FUNCTION: EVP_PKEY_decrypt 2768 1_1_0 EXIST::FUNCTION: