summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-07-27 22:24:33 -0400
committerJune McEnroe <june@causal.agency>2020-07-31 12:12:53 -0400
commit6e5bff1a29b3f93334acd86ca8ab8f10ec61411b (patch)
tree6ebc9d667a15698402f8563d8a85e21d0c89423b
parenttls_server: #include <string.h> (diff)
downloadlibretls-6e5bff1a29b3f93334acd86ca8ab8f10ec61411b.tar.gz
libretls-6e5bff1a29b3f93334acd86ca8ab8f10ec61411b.zip
tls_bio_cb: Use public BIO interfaces
-rw-r--r--tls_bio_cb.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/tls_bio_cb.c b/tls_bio_cb.c
index 0091808..8adbf55 100644
--- a/tls_bio_cb.c
+++ b/tls_bio_cb.c
@@ -17,6 +17,7 @@
 
 #include <fcntl.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include <openssl/bio.h>
@@ -29,19 +30,28 @@ static int bio_cb_read(BIO *bio, char *buf, int size);
 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 BIO_METHOD *bio_cb_method;
+
+static pthread_once_t bio_cb_init_once = PTHREAD_ONCE_INIT;
+
+static void
+bio_s_cb_init(void)
+{
+	bio_cb_method = BIO_meth_new(BIO_TYPE_MEM, "libtls_callbacks");
+	if (bio_cb_method == NULL)
+		return;
+
+	BIO_meth_set_write(bio_cb_method, bio_cb_write);
+	BIO_meth_set_read(bio_cb_method, bio_cb_read);
+	BIO_meth_set_puts(bio_cb_method, bio_cb_puts);
+	BIO_meth_set_ctrl(bio_cb_method, bio_cb_ctrl);
+}
 
 static BIO_METHOD *
 bio_s_cb(void)
 {
-	return (&bio_cb_method);
+	pthread_once(&bio_cb_init_once, bio_s_cb_init);
+	return bio_cb_method;
 }
 
 static int
@@ -57,10 +67,10 @@ bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr)
 
 	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 +79,7 @@ bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr)
 	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 +88,7 @@ bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr)
 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 +106,7 @@ bio_cb_write(BIO *bio, const char *buf, int num)
 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 +141,8 @@ tls_set_cbs(struct tls *ctx, tls_read_cb read_cb, tls_write_cb write_cb,
 		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);
 
='logheader'>2020-02-11Use time_t for save signatureJune McEnroe It's actually more likely to be 64-bit than size_t anyway, and it eliminates some helper functions. Also don't error when reading an empty save file. 2020-02-11Set self.nick to * initiallyJune McEnroe Allows removing a bunch of checks that self.nick is set, and it's what the server usually calls you before registration. Never highlight notices as mentions. 2020-02-11Define ColorCap instead of hardcoding 100June McEnroe 2020-02-11Move hash to top of chat.hJune McEnroe 2020-02-11Move base64 out of chat.hJune McEnroe 2020-02-11Move XDG_SUBDIR out of chat.hJune McEnroe 2020-02-11Fix whois idle unit calculationJune McEnroe Rookie mistake. 2020-02-11Cast towupper to wchar_tJune McEnroe For some reason it takes and returns wint_t... 2020-02-11Cast set but unused variables to voidJune McEnroe 2020-02-11Declare strlcatJune McEnroe 2020-02-11Check if VDSUSP existsJune McEnroe 2020-02-11Fix completeReplace iterationJune McEnroe 2020-02-11Use pkg(8) to configure on FreeBSDJune McEnroe 2020-02-11Remove legacy codeJune McEnroe 2020-02-11Add INSTALLING section to READMEJune McEnroese htmlf with non-formatted stringsChris Mayo Signed-off-by: Chris Mayo <aklhfex@gmail.com> 2019-02-23ui-ssdiff: resolve HTML5 validation errorsChris Mayo - Remove ids from anchor elements. They were unusable because they were duplicated between files and versions of files. - Always close span, with html(). - Fix missing / on closing tr element in cgit_ssdiff_header_end(). Signed-off-by: Chris Mayo <aklhfex@gmail.com> 2019-01-03filters: migrate from luacrypto to luaosslJason A. Donenfeld luaossl has no upstream anymore and doesn't support OpenSSL 1.1, whereas luaossl is quite active. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2019-01-02ui-shared: fix broken sizeof in title setting and rewriteJason A. Donenfeld The old algorithm was totally incorrect. While we're at it, use « instead of \, since it makes more sense. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2018-12-09git: update to v2.20.0Christian Hesse Update to git version v2.20.0. Required changes follow upstream commits: * 00436bf1b1c2a8fe6cf5d2c2457d419d683042f4 (archive: initialize archivers earlier) * 611e42a5980a3a9f8bb3b1b49c1abde63c7a191e (xdiff: provide a separate emit callback for hunks) Signed-off-by: Christian Hesse <mail@eworm.de> 2018-11-25ui-blame: set repo for sbJason A. Donenfeld Otherwise recent git complains and crashes with: "BUG: blame.c:1787: repo is NULL". Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2018-11-25auth-filter: pass url with query string attachedJason A. Donenfeld Otherwise redirections come out wrong. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2018-11-21git: use xz compressed archive for downloadChristian Hesse Upstream will stop providing gz compressed source tarballs [0], so stop using them. [0] https://lists.zx2c4.com/pipermail/cgit/2018-November/004254.html Signed-off-by: Christian Hesse <mail@eworm.de> 2018-10-12git: update to v2.19.1Christian Hesse Update to git version v2.19.1. Required changes follow upstream commits: * commit: add repository argument to get_cached_commit_buffer (3ce85f7e5a41116145179f0fae2ce6d86558d099) * commit: add repository argument to lookup_commit_reference (2122f6754c93be8f02bfb5704ed96c88fc9837a8) * object: add repository argument to parse_object (109cd76dd3467bd05f8d2145b857006649741d5c) * tag: add repository argument to deref_tag (a74093da5ed601a09fa158e5ba6f6f14c1142a3e) * tag: add repository argument to lookup_tag (ce71efb713f97f476a2d2ab541a0c73f684a5db3) * tree: add repository argument to lookup_tree (f86bcc7b2ce6cad68ba1a48a528e380c6126705e) * archive.c: avoid access to the_index (b612ee202a48f129f81f8f6a5af6cf71d1a9caef) * for_each_*_object: move declarations to object-store.h (0889aae1cd18c1804ba01c1a4229e516dfb9fe9b) Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-ssdiff: ban strcat()Christian Hesse Git upstream bans strcat() with commit: banned.h: mark strcat() as banned 1b11b64b815db62f93a04242e4aed5687a448748 Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-ssdiff: ban strncpy()Christian Hesse Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-shared: ban strcat()Christian Hesse Git upstream bans strcat() with commit: banned.h: mark strcat() as banned 1b11b64b815db62f93a04242e4aed5687a448748 To avoid compiler warnings from gcc 8.1.x we get the hard way. Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-patch: ban sprintf()Christian Hesse Git upstream bans sprintf() with commit: banned.h: mark sprintf() as banned cc8fdaee1eeaf05d8dd55ff11f111b815f673c58 Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-log: ban strncpy()Christian Hesse Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-log: ban strcpy()Christian Hesse Git upstream bans strcpy() with commit: automatically ban strcpy() c8af66ab8ad7cd78557f0f9f5ef6a52fd46ee6dd Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11parsing: ban sprintf()Christian Hesse Git upstream bans sprintf() with commit: banned.h: mark sprintf() as banned cc8fdaee1eeaf05d8dd55ff11f111b815f673c58 Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11parsing: ban strncpy()Christian Hesse Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> 2018-08-28filters: generate anchor links from markdownChristian Hesse This makes the markdown filter generate anchor links for headings. Signed-off-by: Christian Hesse <mail@eworm.de> Tested-by: jean-christophe manciot <actionmystique@gmail.com> 2018-08-03Bump version.Jason A. Donenfeld Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2018-08-03clone: fix directory traversalJason A. Donenfeld This was introduced in the initial version of this code, way back when in 2008. $ curl http://127.0.0.1/cgit/repo/objects/?path=../../../../../../../../../etc/passwd root:x:0:0:root:/root:/bin/sh ... Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reported-by: Jann Horn <jannh@google.com> 2018-08-03config: record repo.snapshot-prefix in the per-repo configKonstantin Ryabitsev