From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>,
tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v1 2/2] sql: ignore \0 in string passed to Lua-function
Date: Thu, 1 Apr 2021 15:01:56 +0300 [thread overview]
Message-ID: <20210401120156.GA108111@tarantool.org> (raw)
In-Reply-To: <20210401084102.GA54278@tarantool.org>
Sorry, I found that '\0' in changelog file name was a bad idea. Quite a few
CI runs failed. I renamed this file and force-pushed this patch. Diff below.
On Thu, Apr 01, 2021 at 11:41:02AM +0300, Mergen Imeev via Tarantool-patches wrote:
> On Wed, Mar 31, 2021 at 10:25:23PM +0200, Vladislav Shpilevoy wrote:
> > Good job on the patch!
> Thank you! My answers and new patch below.
>
> >
> > See 2 comments below.
> >
> > 1. Please, add a changelog file.
> Added.
>
> >
> > On 30.03.2021 13:21, Mergen Imeev via Tarantool-patches wrote:
> > > 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));
> >
> > 2. Unary operators should not have a whitespace after them.
> Fixed.
>
> >
> > > break;
> > > case MP_BIN:
> > > case MP_ARRAY:
>
>
> New patch:
>
>
> commit 337a6cddd1d9e70c77e3ba48600b5d5ec9477dd7
> Author: Mergen Imeev <imeevma@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-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.
> 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()
Diff:
commit f13a1b4ddda6b6a26a7140fc67268f0ecf498a64
Author: Mergen Imeev <imeevma@gmail.com>
Date: Thu Apr 1 13:39:12 2021 +0300
Fix
diff --git "a/changelogs/unreleased/fix-crop-strings-by-\\0-in-user-functions.md" b/changelogs/unreleased/fix-string-cropping-in-user-functions.md
similarity index 100%
rename from "changelogs/unreleased/fix-crop-strings-by-\\0-in-user-functions.md"
rename to changelogs/unreleased/fix-string-cropping-in-user-functions.md
next prev parent reply other threads:[~2021-04-01 12:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-30 11:21 [Tarantool-patches] [PATCH v1 0/2] sql: ignore \0 in string passed to user function Mergen Imeev via Tarantool-patches
2021-03-30 11:21 ` [Tarantool-patches] [PATCH v1 1/2] sql: ignore \0 in string passed to C-function Mergen Imeev via Tarantool-patches
2021-03-31 20:25 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-01 8:32 ` Mergen Imeev via Tarantool-patches
2021-03-30 11:21 ` [Tarantool-patches] [PATCH v1 2/2] sql: ignore \0 in string passed to Lua-function Mergen Imeev via Tarantool-patches
2021-03-31 20:25 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-01 8:41 ` Mergen Imeev via Tarantool-patches
2021-04-01 12:01 ` Mergen Imeev via Tarantool-patches [this message]
2021-04-01 19:51 ` Vladislav Shpilevoy via Tarantool-patches
2021-04-01 22:50 ` Mergen Imeev via Tarantool-patches
2021-04-01 23:09 ` [Tarantool-patches] [PATCH v1 0/2] sql: ignore \0 in string passed to user function Vladislav Shpilevoy via Tarantool-patches
2021-04-02 7:55 ` Kirill Yukhin via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210401120156.GA108111@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=imeevma@tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v1 2/2] sql: ignore \0 in string passed to Lua-function' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox