]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Return nil if base32 decode fails
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 2 Jul 2020 15:42:48 +0000 (16:42 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 2 Jul 2020 15:42:48 +0000 (16:42 +0100)
src/lua/lua_util.c

index 70236fc2fb924e798ddd2a6bd0adeff550541cd0..d81c574b7de92333dffe9b1b9ee58c9b485bef1d 100644 (file)
@@ -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);