[Tarantool-patches] [PATCH v1 2/2] sql: ignore \0 in string passed to Lua-function
Mergen Imeev
imeevma at tarantool.org
Fri Apr 2 01:50:10 MSK 2021
Hi! Thank you for the review. My asnwer and new patch below.
On Thu, Apr 01, 2021 at 09:51:06PM +0200, Vladislav Shpilevoy wrote:
> Hi! Thanks for the fixes!
>
> > diff --git "a/changelogs/unreleased/fix-crop-strings-by-\\0-in-user-functions.md" "b/changelogs/unreleased/fix-crop-strings-by-\\0-in-user-functions.md"
> > new file mode 100644
> > index 000000000..a0aa8a425
> > --- /dev/null
> > +++ "b/changelogs/unreleased/fix-crop-strings-by-\\0-in-user-functions.md"
> > @@ -0,0 +1,4 @@
> > +## bugfix/sql
> > +
> > +* Fixed cropping of a string if it contains '\0' when passing a string
> > + to user-defined Lua or C functions.
>
> In the changelog records we use imperative, like in commit titles (because it
> seems to be a commonly used way of writing them). Also you need to add the
> issue reference to the text in a form `(gh-####)`. Look at the other changelog
> files for examples.
Thank you. Fixed.
New patch:
commit 3a9ba7639621c0afd8af1e4de8ef6bb639edeb6e
Author: Mergen Imeev <imeevma at gmail.com>
Date: Tue Mar 30 09:41:34 2021 +0300
sql: ignore \0 in string passed to Lua-function
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
diff --git a/changelogs/unreleased/fix-string-cropping-in-user-functions.md b/changelogs/unreleased/fix-string-cropping-in-user-functions.md
new file mode 100644
index 000000000..f883aa0e0
--- /dev/null
+++ b/changelogs/unreleased/fix-string-cropping-in-user-functions.md
@@ -0,0 +1,5 @@
+## bugfix/sql
+
+* The string received by the user-defined C or Lua function could be different
+ from the string passed to the function. This could happen if the string passed
+ from SQL contains '\0' (gh-5938).
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index c3c14bd22..9b6179f3a 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()
More information about the Tarantool-patches
mailing list