# HG changeset patch # User Matthew Wild # Date 1779718307 -3600 # Node ID 25beb66fab3836138ecdf22dc1c6440416158c72 # Parent af87d31dcae40ae38e5ae4adac8fd9e0d44ce5d4 util.crypto: Use post-Lua 5.1 buffer API Tha Lua 5.1 buffer API was frustrating to work with. luaL_prepbuffer() only allocates LUAL_BUFFERSIZE - there is no way to request a specific size. LUAL_BUFFERSIZE is set to BUFSIZ by default, which is generally 8192 bytes on Linux, however it may vary between platforms. The variation means this buffer could potentially overflow (small BUFSIZ with large signature). The Lua 5.2+ buffer API enables requesting a specific buffer size, so that's what we do now. diff -r af87d31dcae4 -r 25beb66fab38 util-src/crypto.c --- a/util-src/crypto.c Mon May 25 14:51:15 2026 +0100 +++ b/util-src/crypto.c Mon May 25 15:11:47 2026 +0100 @@ -150,16 +150,13 @@ return 1; } - // COMPAT w/ Lua 5.1 - luaL_buffinit(L, &sigbuf); - sig = memset(luaL_prepbuffer(&sigbuf), 0, sig_len); + sig = (unsigned char *)luaL_buffinitsize(L, &sigbuf, sig_len); if(EVP_DigestSign(md_ctx, sig, &sig_len, msg, msg_len) != 1) { lua_pushnil(L); } else { - luaL_addsize(&sigbuf, sig_len); - luaL_pushresult(&sigbuf); + luaL_pushresultsize(&sigbuf, sig_len); return 1; }