diff options
author | Matt Caswell <matt@openssl.org> | 2023-09-21 11:59:58 +0100 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2023-09-25 07:46:45 +1000 |
commit | a18c9f80916134bd7122cc1ba204bb5cdca752a3 (patch) | |
tree | da986fec6d29e13a89e454454150f86099b293e7 | |
parent | 442d08f215c48896f59e9c09a14773058f9e56bf (diff) |
Implement a public BIO_ADDR_copy() function
We already have BIO_ADDR_dup() but in some contexts that is not sufficent.
We implement BIO_ADDR_copy() and make BIO_ADDR_dup() use it.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22164)
-rw-r--r-- | crypto/bio/bio_addr.c | 19 | ||||
-rw-r--r-- | include/openssl/bio.h.in | 1 | ||||
-rw-r--r-- | util/libcrypto.num | 1 |
3 files changed, 19 insertions, 2 deletions
diff --git a/crypto/bio/bio_addr.c b/crypto/bio/bio_addr.c index aec94237fc..2a6f6d522c 100644 --- a/crypto/bio/bio_addr.c +++ b/crypto/bio/bio_addr.c @@ -65,14 +65,29 @@ void BIO_ADDR_free(BIO_ADDR *ap) OPENSSL_free(ap); } +int BIO_ADDR_copy(BIO_ADDR *dst, const BIO_ADDR *src) +{ + if (dst == NULL || src == NULL) + return 0; + + if (src->sa.sa_family == AF_UNSPEC) { + BIO_ADDR_clear(dst); + return 1; + } + + return BIO_ADDR_make(dst, &src->sa); +} + BIO_ADDR *BIO_ADDR_dup(const BIO_ADDR *ap) { BIO_ADDR *ret = NULL; if (ap != NULL) { ret = BIO_ADDR_new(); - if (ret != NULL) - BIO_ADDR_make(ret, &ap->sa); + if (ret != NULL && !BIO_ADDR_copy(ret, ap)) { + BIO_ADDR_free(ret); + ret = NULL; + } } return ret; } diff --git a/include/openssl/bio.h.in b/include/openssl/bio.h.in index 8aad141446..c534dcd76c 100644 --- a/include/openssl/bio.h.in +++ b/include/openssl/bio.h.in @@ -806,6 +806,7 @@ int BIO_hex_string(BIO *out, int indent, int width, const void *data, # ifndef OPENSSL_NO_SOCK BIO_ADDR *BIO_ADDR_new(void); +int BIO_ADDR_copy(BIO_ADDR *dst, const BIO_ADDR *src); BIO_ADDR *BIO_ADDR_dup(const BIO_ADDR *ap); int BIO_ADDR_rawmake(BIO_ADDR *ap, int family, const void *where, size_t wherelen, unsigned short port); diff --git a/util/libcrypto.num b/util/libcrypto.num index e4265b4cef..6af1fe1707 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -5535,3 +5535,4 @@ OSSL_ERR_STATE_save_to_mark ? 3_2_0 EXIST::FUNCTION: X509_STORE_CTX_set_get_crl ? 3_2_0 EXIST::FUNCTION: X509_STORE_CTX_set_current_reasons ? 3_2_0 EXIST::FUNCTION: OSSL_STORE_delete ? 3_2_0 EXIST::FUNCTION: +BIO_ADDR_copy ? 3_2_0 EXIST::FUNCTION:SOCK |