From: Vsevolod Stakhov Date: Fri, 18 Nov 2016 09:26:59 +0000 (+0000) Subject: [Fix] Fix hash creation X-Git-Tag: 1.4.0~27 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=567ecaebd920e7734239d1abd4b0a55521bf0e5c;p=rspamd.git [Fix] Fix hash creation --- diff --git a/src/lua/lua_cryptobox.c b/src/lua/lua_cryptobox.c index efda2b2a7..aa46b1e66 100644 --- a/src/lua/lua_cryptobox.c +++ b/src/lua/lua_cryptobox.c @@ -682,14 +682,11 @@ lua_cryptobox_hash_create (lua_State *L) gsize len = 0; h = rspamd_lua_hash_create (NULL); - ph = lua_newuserdata (L, sizeof (void *)); - *ph = h; - rspamd_lua_setclass (L, "rspamd{cryptobox_hash}", -1); if (lua_type (L, 1) == LUA_TSTRING) { s = lua_tolstring (L, 1, &len); } - else if (lua_isuserdata (L, 1)) { + else if (lua_type (L, 1) == LUA_TUSERDATA) { t = lua_check_text (L, 1); if (!t) { @@ -704,6 +701,10 @@ lua_cryptobox_hash_create (lua_State *L) rspamd_lua_hash_update (h, s, len); } + ph = lua_newuserdata (L, sizeof (void *)); + *ph = h; + rspamd_lua_setclass (L, "rspamd{cryptobox_hash}", -1); + return 1; } @@ -727,14 +728,11 @@ lua_cryptobox_hash_create_specific (lua_State *L) } h = rspamd_lua_hash_create (type); - ph = lua_newuserdata (L, sizeof (void *)); - *ph = h; - rspamd_lua_setclass (L, "rspamd{cryptobox_hash}", -1); if (lua_type (L, 2) == LUA_TSTRING) { s = lua_tolstring (L, 2, &len); } - else if (lua_isuserdata (L, 2)) { + else if (lua_type (L, 2) == LUA_TUSERDATA) { t = lua_check_text (L, 2); if (!t) { @@ -749,6 +747,10 @@ lua_cryptobox_hash_create_specific (lua_State *L) rspamd_lua_hash_update (h, s, len); } + ph = lua_newuserdata (L, sizeof (void *)); + *ph = h; + rspamd_lua_setclass (L, "rspamd{cryptobox_hash}", -1); + return 1; } @@ -772,14 +774,11 @@ lua_cryptobox_hash_create_keyed (lua_State *L) if (key != NULL) { h = rspamd_lua_hash_create (NULL); rspamd_cryptobox_hash_init (h->h, key, keylen); - ph = lua_newuserdata (L, sizeof (void *)); - *ph = h; - rspamd_lua_setclass (L, "rspamd{cryptobox_hash}", -1); if (lua_type (L, 2) == LUA_TSTRING) { s = lua_tolstring (L, 2, &len); } - else if (lua_isuserdata (L, 2)) { + else if (lua_type (L, 2) == LUA_TUSERDATA) { t = lua_check_text (L, 2); if (!t) { @@ -793,6 +792,10 @@ lua_cryptobox_hash_create_keyed (lua_State *L) if (s) { rspamd_cryptobox_hash_update (h, s, len); } + + ph = lua_newuserdata (L, sizeof (void *)); + *ph = h; + rspamd_lua_setclass (L, "rspamd{cryptobox_hash}", -1); } else { return luaL_error (L, "invalid arguments");