BIO_get_new_index() is static counter meant to get index for custom bio type definition. As we can read in the documentation: > Note that BIO_get_new_index() can only be used 127 times before it > returns an error. We cannot call it repeatedly, because it will fail eventually. To my understanding the index is not needed in our use and we could safely use BIO_TYPE_NONE. Documentation states: > type can be set to either BIO_TYPE_NONE or via BIO_get_new_index() if > a unique type is required for searching (See BIO_find_type(3)) We don't use any search related functions. This reverts commit 816dad231f5b312fd98e81cc6a6cbaf47c1e26a5. Fixes: https://github.com/mpv-player/mpv/issues/16589
Unified · Split
| @@ -659,14 +659,11 @@ static int url_bio_bputs(BIO *b, const char *str) · 658 unmodified lines | |||
| 659 | return url_bio_bwrite(b, str, strlen(str)); | 659 | return url_bio_bwrite(b, str, strlen(str)); |
| 660 | } | 660 | } |
| 661 | 661 | ||
| 662 | static av_cold int init_bio_method(URLContext *h) | 662 | static av_cold void init_bio_method(URLContext *h) |
| 663 | { | 663 | { |
| 664 | TLSContext *p = h->priv_data; | 664 | TLSContext *p = h->priv_data; |
| 665 | BIO *bio; | 665 | BIO *bio; |
| 666 | int bio_idx = BIO_get_new_index(); | 666 | p->url_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK, "urlprotocol bio"); |
| 667 | if (bio_idx == -1) | ||
| 668 | return AVERROR_EXTERNAL; | ||
| 669 | p->url_bio_method = BIO_meth_new(bio_idx | BIO_TYPE_SOURCE_SINK, "urlprotocol bio"); | ||
| 670 | BIO_meth_set_write(p->url_bio_method, url_bio_bwrite); | 667 | BIO_meth_set_write(p->url_bio_method, url_bio_bwrite); |
| 671 | BIO_meth_set_read(p->url_bio_method, url_bio_bread); | 668 | BIO_meth_set_read(p->url_bio_method, url_bio_bread); |
| 672 | BIO_meth_set_puts(p->url_bio_method, url_bio_bputs); | 669 | BIO_meth_set_puts(p->url_bio_method, url_bio_bputs); |
| @@ -677,7 +674,6 @@ static av_cold int init_bio_method(URLContext *h) · 4 unmodified lines | |||
| 677 | BIO_set_data(bio, p); | 674 | BIO_set_data(bio, p); |
| 678 | 675 | ||
| 679 | SSL_set_bio(p->ssl, bio, bio); | 676 | SSL_set_bio(p->ssl, bio, bio); |
| 680 | return 0; | ||
| 681 | } | 677 | } |
| 682 | 678 | ||
| 683 | static void openssl_info_callback(const SSL *ssl, int where, int ret) { | 679 | static void openssl_info_callback(const SSL *ssl, int where, int ret) { |
| @@ -874,11 +870,7 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary ** · 190 unmodified lines | |||
| 874 | SSL_set_options(p->ssl, SSL_OP_NO_QUERY_MTU); | 870 | SSL_set_options(p->ssl, SSL_OP_NO_QUERY_MTU); |
| 875 | SSL_set_mtu(p->ssl, c->mtu); | 871 | SSL_set_mtu(p->ssl, c->mtu); |
| 876 | DTLS_set_link_mtu(p->ssl, c->mtu); | 872 | DTLS_set_link_mtu(p->ssl, c->mtu); |
| 877 | 873 | init_bio_method(h); | |
| 878 | ret = init_bio_method(h); | ||
| 879 | if (ret < 0) | ||
| 880 | goto fail; | ||
| 881 | |||
| 882 | if (p->tls_shared.external_sock != 1) { | 874 | if (p->tls_shared.external_sock != 1) { |
| 883 | if ((ret = ff_tls_open_underlying(&p->tls_shared, h, url, options)) < 0) { | 875 | if ((ret = ff_tls_open_underlying(&p->tls_shared, h, url, options)) < 0) { |
| 884 | av_log(p, AV_LOG_ERROR, "Failed to connect %s\n", url); | 876 | av_log(p, AV_LOG_ERROR, "Failed to connect %s\n", url); |
| @@ -956,9 +948,7 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op · 71 unmodified lines | |||
| 956 | } | 948 | } |
| 957 | SSL_set_ex_data(p->ssl, 0, p); | 949 | SSL_set_ex_data(p->ssl, 0, p); |
| 958 | SSL_CTX_set_info_callback(p->ctx, openssl_info_callback); | 950 | SSL_CTX_set_info_callback(p->ctx, openssl_info_callback); |
| 959 | ret = init_bio_method(h); | 951 | init_bio_method(h); |
| 960 | if (ret < 0) | ||
| 961 | goto fail; | ||
| 962 | if (!c->listen && !c->numerichost) { | 952 | if (!c->listen && !c->numerichost) { |
| 963 | // By default OpenSSL does too lax wildcard matching | 953 | // By default OpenSSL does too lax wildcard matching |
| 964 | SSL_set_hostflags(p->ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); | 954 | SSL_set_hostflags(p->ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); |