From 56129a44f9f72091ab2b500746f3d0a47ee88b5c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 2 Jul 2020 16:42:48 +0100 Subject: [Minor] Return nil if base32 decode fails --- src/lua/lua_util.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 70236fc2f..d81c574b7 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -1232,11 +1232,20 @@ lua_util_decode_base32 (lua_State *L) } if (s != NULL) { - t = lua_newuserdata (L, sizeof (*t)); - rspamd_lua_setclass (L, "rspamd{text}", -1); - t->start = rspamd_decode_base32 (s, inlen, &outlen, btype); - t->len = outlen; - t->flags = RSPAMD_TEXT_FLAG_OWN; + guchar *decoded; + + decoded = rspamd_decode_base32 (s, inlen, &outlen, btype); + + if (decoded) { + t = lua_newuserdata (L, sizeof (*t)); + rspamd_lua_setclass (L, "rspamd{text}", -1); + t->start = (const gchar *)decoded; + t->len = outlen; + t->flags = RSPAMD_TEXT_FLAG_OWN; + } + else { + lua_pushnil (L); + } } else { lua_pushnil (L); -- cgit v1.2.3