commit e85cbc4: [Minor] Allow lua_text for opaque transition

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Jul 4 11:07:06 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-07-04 12:01:57 +0100
URL: https://github.com/rspamd/rspamd/commit/e85cbc442332876f48a4e0073f18bf821775a38e

[Minor] Allow lua_text for opaque transition

---
 src/lua/lua_worker.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/lua/lua_worker.c b/src/lua/lua_worker.c
index 8b69b71ef..273bcb63b 100644
--- a/src/lua/lua_worker.c
+++ b/src/lua/lua_worker.c
@@ -292,7 +292,7 @@ rspamd_lua_execute_lua_subprocess (lua_State *L,
 {
 	gint err_idx, r;
 	guint64 wlen = 0;
-	const gchar *ret;
+	const gchar *ret = NULL;
 	gsize retlen;
 
 	lua_pushcfunction (L, &rspamd_lua_traceback);
@@ -319,15 +319,27 @@ rspamd_lua_execute_lua_subprocess (lua_State *L,
 		}
 	}
 	else {
-		ret = lua_tolstring (L, -1, &retlen);
-		wlen = retlen;
+		if (lua_type (L, -1) == LUA_TSTRING) {
+			ret = lua_tolstring (L, -1, &retlen);
+			wlen = retlen;
+		}
+		else {
+			struct rspamd_lua_text *t;
+
+			t = lua_check_text (L, -1);
+
+			if (t) {
+				ret = t->start;
+				wlen = t->len;
+			}
+		}
 
 		r = write (cbdata->sp[1], &wlen, sizeof (wlen));
 		if (r == -1) {
 			msg_err ("write failed: %s", strerror (errno));
 		}
 
-		r = write (cbdata->sp[1], ret, retlen);
+		r = write (cbdata->sp[1], ret, wlen);
 		if (r == -1) {
 			msg_err ("write failed: %s", strerror (errno));
 		}


More information about the Commits mailing list