aboutsummaryrefslogtreecommitdiffstats
path: root/main/libtls-standalone/openssl-1.1.0-bio-method.patch
blob: 4f4290c3ceab6fe98dbfa08033b0a5bf0a67128f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--- libressl-2.7.4.orig/tls/tls_bio_cb.c
+++ libressl-2.7.4/tls/tls_bio_cb.c
@@ -18,6 +18,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <assert.h>
 
 #include <openssl/bio.h>
 
@@ -29,19 +30,36 @@
 static int bio_cb_puts(BIO *bio, const char *str);
 static long bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr);
 
-static BIO_METHOD bio_cb_method = {
-	.type = BIO_TYPE_MEM,
-	.name = "libtls_callbacks",
-	.bwrite = bio_cb_write,
-	.bread = bio_cb_read,
-	.bputs = bio_cb_puts,
-	.ctrl = bio_cb_ctrl,
-};
+static pthread_once_t bio_cb_init_once = PTHREAD_ONCE_INIT;
 
+static BIO_METHOD *bio_cb_method = NULL;
+
+static void
+bio_s_cb_init(void)
+{
+	BIO_METHOD *method;
+
+	method = BIO_meth_new(BIO_TYPE_MEM, "libtls_callbacks");
+	assert(method != NULL);
+
+	BIO_meth_set_read(method, bio_cb_read);
+	BIO_meth_set_write(method, bio_cb_write);
+	BIO_meth_set_puts(method, bio_cb_puts);
+	BIO_meth_set_ctrl(method, bio_cb_ctrl);
+
+	bio_cb_method = method;
+}
+
 static BIO_METHOD *
 bio_s_cb(void)
 {
-	return (&bio_cb_method);
+	if (bio_cb_method != NULL) {
+		return bio_cb_method;
+	}
+
+	(void) pthread_once(&bio_cb_init_once, bio_s_cb_init);
+
+	return bio_cb_method;
 }
 
 static int
@@ -57,10 +75,10 @@
 
 	switch (cmd) {
 	case BIO_CTRL_GET_CLOSE:
-		ret = (long)bio->shutdown;
+		ret = (long) BIO_get_shutdown(bio);
 		break;
 	case BIO_CTRL_SET_CLOSE:
-		bio->shutdown = (int)num;
+		BIO_set_shutdown(bio, (int) num);
 		break;
 	case BIO_CTRL_DUP:
 	case BIO_CTRL_FLUSH:
@@ -69,7 +87,7 @@
 	case BIO_CTRL_GET:
 	case BIO_CTRL_SET:
 	default:
-		ret = BIO_ctrl(bio->next_bio, cmd, num, ptr);
+		ret = BIO_ctrl(BIO_next(bio), cmd, num, ptr);
 	}
 
 	return (ret);
@@ -78,7 +96,7 @@
 static int
 bio_cb_write(BIO *bio, const char *buf, int num)
 {
-	struct tls *ctx = bio->ptr;
+	struct tls *ctx = BIO_get_data(bio);
 	int rv;
 
 	BIO_clear_retry_flags(bio);
@@ -96,7 +114,7 @@
 static int
 bio_cb_read(BIO *bio, char *buf, int size)
 {
-	struct tls *ctx = bio->ptr;
+	struct tls *ctx = BIO_get_data(bio);
 	int rv;
 
 	BIO_clear_retry_flags(bio);
@@ -131,8 +149,8 @@
 		tls_set_errorx(ctx, "failed to create callback i/o");
 		goto err;
 	}
-	bio->ptr = ctx;
-	bio->init = 1;
+	BIO_set_data(bio, ctx);
+	BIO_set_init(bio, 1);
 
 	SSL_set_bio(ctx->ssl_conn, bio, bio);