summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2017-01-12 16:17:22 +0000
committerjsing <>2017-01-12 16:17:22 +0000
commitacd4f5e048d0b4064c70fb20526265939903fc62 (patch)
treed1fc24eafecc960a0aecff386c4a8419809b4919
parent58d82b289db469d336d518a0e13669ca30ed96f7 (diff)
downloadopenbsd-acd4f5e048d0b4064c70fb20526265939903fc62.tar.gz
openbsd-acd4f5e048d0b4064c70fb20526265939903fc62.tar.bz2
openbsd-acd4f5e048d0b4064c70fb20526265939903fc62.zip
Inline tls_get_new_cb_bio() from the only place that it gets called,
simplifying the code. Also check the provided read and write callbacks before assigning to the context.
-rw-r--r--src/lib/libtls/tls_bio_cb.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/lib/libtls/tls_bio_cb.c b/src/lib/libtls/tls_bio_cb.c
index 75d9685cb3..034cbd60bf 100644
--- a/src/lib/libtls/tls_bio_cb.c
+++ b/src/lib/libtls/tls_bio_cb.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls_bio_cb.c,v 1.17 2017/01/12 16:08:49 jsing Exp $ */ 1/* $OpenBSD: tls_bio_cb.c,v 1.18 2017/01/12 16:17:22 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2016 Tobias Pape <tobias@netshed.de> 3 * Copyright (c) 2016 Tobias Pape <tobias@netshed.de>
4 * 4 *
@@ -114,26 +114,6 @@ bio_cb_read(BIO *bio, char *buf, int size)
114 return (rv); 114 return (rv);
115} 115}
116 116
117static BIO *
118tls_get_new_cb_bio(struct tls *ctx)
119{
120 BIO *bio;
121
122 if (ctx->read_cb == NULL || ctx->write_cb == NULL) {
123 tls_set_errorx(ctx, "no callbacks registered");
124 return (NULL);
125 }
126 if ((bio = BIO_new(bio_s_cb())) == NULL) {
127 tls_set_errorx(ctx, "failed to create callback i/o");
128 return (NULL);
129 }
130
131 bio->ptr = ctx;
132 bio->init = 1;
133
134 return (bio);
135}
136
137int 117int
138tls_set_cbs(struct tls *ctx, tls_read_cb read_cb, tls_write_cb write_cb, 118tls_set_cbs(struct tls *ctx, tls_read_cb read_cb, tls_write_cb write_cb,
139 void *cb_arg) 119 void *cb_arg)
@@ -141,12 +121,21 @@ tls_set_cbs(struct tls *ctx, tls_read_cb read_cb, tls_write_cb write_cb,
141 int rv = -1; 121 int rv = -1;
142 BIO *bio; 122 BIO *bio;
143 123
124 if (read_cb == NULL || write_cb == NULL) {
125 tls_set_errorx(ctx, "no callbacks provided");
126 goto err;
127 }
128
144 ctx->read_cb = read_cb; 129 ctx->read_cb = read_cb;
145 ctx->write_cb = write_cb; 130 ctx->write_cb = write_cb;
146 ctx->cb_arg = cb_arg; 131 ctx->cb_arg = cb_arg;
147 132
148 if ((bio = tls_get_new_cb_bio(ctx)) == NULL) 133 if ((bio = BIO_new(bio_s_cb())) == NULL) {
134 tls_set_errorx(ctx, "failed to create callback i/o");
149 goto err; 135 goto err;
136 }
137 bio->ptr = ctx;
138 bio->init = 1;
150 139
151 SSL_set_bio(ctx->ssl_conn, bio, bio); 140 SSL_set_bio(ctx->ssl_conn, bio, bio);
152 141