[Tarantool-patches] [PATCH v1 2/2] sql: ignore \0 in string passed to Lua-function
imeevma at tarantool.org
imeevma at tarantool.org
Tue Mar 30 14:21:55 MSK 2021
Prior to this patch string passed to user-defined Lua-function from SQL
was cropped in case it contains '\0'. At the same time, it wasn't
cropped if it is passed to the function from BOX. After this patch the
string won't be cropped when passed from SQL if it contain '\0'.
Closes #5938
---
src/box/sql/func.c | 3 ++-
.../gh-5938-wrong-string-length.test.lua | 19 ++++++++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index c3c14bd22..7d5a55d3f 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -120,7 +120,8 @@ port_vdbemem_dump_lua(struct port *base, struct lua_State *L, bool is_flat)
lua_pushnumber(L, sql_value_double(param));
break;
case MP_STR:
- lua_pushstring(L, (const char *) sql_value_text(param));
+ lua_pushlstring(L, (const char *) sql_value_text(param),
+ (size_t) sql_value_bytes(param));
break;
case MP_BIN:
case MP_ARRAY:
diff --git a/test/sql-tap/gh-5938-wrong-string-length.test.lua b/test/sql-tap/gh-5938-wrong-string-length.test.lua
index 943389e34..415fc7729 100755
--- a/test/sql-tap/gh-5938-wrong-string-length.test.lua
+++ b/test/sql-tap/gh-5938-wrong-string-length.test.lua
@@ -3,7 +3,7 @@ local build_path = os.getenv("BUILDDIR")
package.cpath = build_path..'/test/sql-tap/?.so;'..build_path..'/test/sql-tap/?.dylib;'..package.cpath
local test = require("sqltester")
-test:plan(1)
+test:plan(2)
box.schema.func.create("gh-5938-wrong-string-length.ret_str", {
language = "C",
@@ -25,4 +25,21 @@ test:do_execsql_test(
"This is a complete string","This is a cropped\0 string"
})
+box.schema.func.create("ret_str", {
+ language = "Lua",
+ body = [[function(str) return str end]],
+ param_list = { "string" },
+ returns = "string",
+ exports = { "LUA", "SQL" },
+ is_deterministic = true
+})
+
+test:do_execsql_test(
+ "gh-5938-2",
+ [[
+ SELECT "ret_str"(s) from t;
+ ]], {
+ "This is a complete string","This is a cropped\0 string"
+ })
+
test:finish_test()
--
2.25.1
More information about the Tarantool-patches
mailing list