From 975c6c8c0ab90a65f25af36452d8cf2de3d64177 Mon Sep 17 00:00:00 2001 From: s0ph0s Date: Wed, 28 Feb 2024 22:30:34 -0500 Subject: [PATCH] Finish writing documentation, fix segfaults? --- tool/net/definitions.lua | 22 +++++++++++++++++++++- tool/net/redbean.c | 6 ++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tool/net/definitions.lua b/tool/net/definitions.lua index ead9c3ed2..61e1d76bc 100644 --- a/tool/net/definitions.lua +++ b/tool/net/definitions.lua @@ -7985,7 +7985,27 @@ function unix.Errno:__tostring() end ---@param hostname string for validating that the hostname on the certificate matches what is expected ---@return crypto.tls.Connection ---@nodiscard -function crypto.tls.wrap(fd, hostname) +function crypto.tls.wrap(fd, hostname) end + +--- Read data from the TLS connection. +--- +--- This call is blocking. +---@param bufsize integer # the maximum amount of data to read from the connection. +---@return string # any data read from the connection. +function crypto.tls.Connection:read() end + +--- Write data to the TLS connection. +--- +--- This call is blocking. +---@param data string # the data to write to the connection. +---@return nil +function crypto.tls.Connectino:write() end + +--- Close the connection. +--- +--- Also closes the underlying socket. +---@return nil +function crypto.tls.Connection:close() end -- CONSTANTS ---@type integer for debug logging level. See `Log`. diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 3c97af5ae..4cfd4f5e4 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -5159,13 +5159,15 @@ int LuaCryptoTlsConnectionRead(lua_State *L) { lua_Integer bufsiz; bufsiz = luaL_optinteger(L, 2, BUFSIZ); bufsiz = MIN(bufsiz, 0x7ffff00); - buf = _gc(malloc(bufsiz)); + buf = malloc(bufsiz); rc = TlsConnectionRead(GetTlsConnection(L), buf, bufsiz); if (rc != -1) { got = rc; lua_pushlstring(L, buf, got); + free(buf); return 1; } else { + free(buf); return 0; } } @@ -5229,7 +5231,7 @@ int LuaCryptoTlsWrap(lua_State *L) { } else if (rc == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) { lua_pop(L, 1); return LuaNilTlsError( - L, _gc(DescribeSslVerifyFailure(conn->ctx.session_negotiate->verify_result)), rc + L, DescribeSslVerifyFailure(conn->ctx.session_negotiate->verify_result), rc ); } else { lua_pop(L, 1);