]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix failures in OpenSSL 3.0 with custom logging BIOs
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 28 Mar 2022 19:31:42 +0000 (13:31 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 28 Mar 2022 19:31:42 +0000 (13:31 -0600)
Apparently the create callbacks need to call BIO_set_init() otherwise all operations on the BIO will fail.  This isn't documented anywhere.

src/lib/tls/bio.c
src/lib/tls/log.c

index 8177f87d7a1dc44ab1f14c89b3644b5102e62bc2..a9ac84523c992e12c05d243505cd9a985154f6d1 100644 (file)
@@ -375,6 +375,11 @@ int fr_tls_bio_init(void)
        tls_bio_talloc_meth = BIO_meth_new(BIO_get_new_index() | BIO_TYPE_SOURCE_SINK, "fr_tls_bio_dbuff_t");
        if (unlikely(!tls_bio_talloc_meth)) return -1;
 
+       /*
+        *      If BIO_meth_set_create is ever used here be sure to call
+        *      BIO_set_init(bio, 1); in the create callbacks else all
+        *      operations on the BIO will fail.
+        */
        BIO_meth_set_write(tls_bio_talloc_meth, _tls_bio_talloc_write_cb);
        BIO_meth_set_puts(tls_bio_talloc_meth, _tls_bio_talloc_puts_cb);
        BIO_meth_set_read(tls_bio_talloc_meth, _tls_bio_talloc_read_cb);
index d26be319a3beea192e2715d42804c73144cf10ae..d1b9ad4123c5f1cd85455b3abd673325a8eff205 100644 (file)
@@ -555,9 +555,10 @@ void tls_log_clear(void)
 /** Increment the bio meth reference counter
  *
  */
-static int tls_log_request_bio_create_cb(UNUSED BIO *bio)
+static int tls_log_request_bio_create_cb(BIO *bio)
 {
        atomic_fetch_add(&tls_request_log_ref, 1);
+       BIO_set_init(bio, 1);
        return 1;
 }
 
@@ -638,18 +639,20 @@ static int tls_log_request_bio_puts_cb(BIO *bio, char const *in)
 /** Decrement the bio meth reference counter
  *
  */
-static int tls_log_request_bio_free_cb(UNUSED BIO *bio)
+static int tls_log_request_bio_free_cb(BIO *bio)
 {
        atomic_fetch_sub(&tls_request_log_ref, 1);
+       BIO_set_init(bio, 0);
        return 1;
 }
 
 /** Increment the bio meth reference counter
  *
  */
-static int tls_log_global_bio_create_cb(UNUSED BIO *bio)
+static int tls_log_global_bio_create_cb(BIO *bio)
 {
        atomic_fetch_add(&tls_global_log_ref, 1);
+       BIO_set_init(bio, 1);
        return 1;
 }
 
@@ -720,9 +723,10 @@ static int tls_log_global_bio_puts_cb(BIO *bio, char const *in)
 /** Decrement the bio meth reference counter
  *
  */
-static int tls_log_global_bio_free_cb(UNUSED BIO *bio)
+static int tls_log_global_bio_free_cb(BIO *bio)
 {
        atomic_fetch_sub(&tls_global_log_ref, 1);
+       BIO_set_init(bio, 0);
        return 1;
 }