From 803c13219a6f65eee26bf0498416cacd65f711ea Mon Sep 17 00:00:00 2001 From: s0ph0s Date: Sun, 17 Dec 2023 20:53:24 -0500 Subject: [PATCH] Fix segfault I forgot to call `mbedtls_ssl_init()`, oops. --- tool/net/redbean.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 2c06079a5..47c704a3a 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -5072,8 +5072,8 @@ typedef struct TlsConnection_s { int TlsConnectionSetup(TlsConnection *conn, int sock, const char *hostname) { int ret; if (!sslinitialized) TlsInit(); - // TODO(s0ph0s): Do I need to check any errors here? - mbedtls_ssl_setup(&(conn->ctx), &confcli); + mbedtls_ssl_init(&(conn->ctx)); + DCHECK_EQ(0, mbedtls_ssl_setup(&(conn->ctx), &confcli)); if (!evadedragnetsurveillance) { mbedtls_ssl_set_hostname(&(conn->ctx), hostname); } @@ -5106,9 +5106,9 @@ int TlsConnectionSetup(TlsConnection *conn, int sock, const char *hostname) { /** * Write data to a TLS connection. * - * @param conn A TlsConnection that has alreday been setup. - * @param buf Arbitrary data that should be encrypted and sent on the connection. - * @param len The number of bytes of data in the buffer that should be sent. + * @param C A TlsConnection that has alreday been setup. + * @param B Arbitrary data that should be encrypted and sent on the connection. + * @param L The number of bytes of data in the buffer that should be sent. * @return >0 if the write was successful, 0 or less if the write failed. * Values greater than 0 indicate the number of bytes written. */ @@ -5117,9 +5117,9 @@ int TlsConnectionSetup(TlsConnection *conn, int sock, const char *hostname) { /** * Read data from a TLS connection. * - * @param conn A TlsConnection that has alreday been setup. - * @param buf A buffer into which to write the received data. - * @param len The maximum number of bytes to read. `buf` must be at least this big. + * @param C A TlsConnection that has alreday been setup. + * @param B A buffer into which to write the received data. + * @param L The maximum number of bytes to read. `buf` must be at least this big. * @return >0 if the read was successful, 0 or less if the read failed. Values greater * than 0 indicate the number of bytes read. */ @@ -5133,9 +5133,9 @@ int TlsConnectionSetup(TlsConnection *conn, int sock, const char *hostname) { * @return 1 */ int TlsConnectionClose(TlsConnection *conn) { + mbedtls_ssl_free(&(conn->ctx)); // TODO(s0ph0s): loop on EINTR close(conn->bio.fd); - mbedtls_ssl_free(&(conn->ctx)); return 1; }