From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id A25966EC60; Thu, 1 Apr 2021 15:01:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A25966EC60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617278518; bh=iCeiUmDKNXPeqFW5+nKbPcVK2A8PGArVEyjBNfvqn3o=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=BHVuc3iMUQEJ8oAWqHBvJ6apx/tefMLo8wWwHV67/s1/88bRRI7rnrQiGP6yBMAYJ lzULUKUMGzShgTYyqca6PPqXg9M6Qx0ylp0259ChW+xrYPW+5KSWrU/iYP1G27Fcll iwQaq2+1y/mjXOQ84fS13YS/uVNedzKOzst8dTwE= Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id DAC7E6EC60 for ; Thu, 1 Apr 2021 15:01:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DAC7E6EC60 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1lRw1N-0001Gu-6g; Thu, 01 Apr 2021 15:01:57 +0300 Date: Thu, 1 Apr 2021 15:01:56 +0300 To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org Message-ID: <20210401120156.GA108111@tarantool.org> References: <446a9874ec7289914571b7989a194939747d46a7.1617101707.git.imeevma@gmail.com> <20210401084102.GA54278@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210401084102.GA54278@tarantool.org> X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9ED7173E37F4E32947A0146560F8BA709E798FFD99D1B1662182A05F538085040FB742870FF15CC68023EE523B8F162DBAED6D2A222EDE8D5931D14FE1D73FE24 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7922E451CE6E839B1EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378556F4CD9D953FFE8638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95CE99938B3FD79E1DFDBE340D42E8A3326AD0702E4A30213D4A471835C12D1D9774AD6D5ED66289B5259CC434672EE6371117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658359CC434672EE6371117882F4460429728AD0CFFFB425014E868A13BD56FB6657E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F79006372BF47D31460A3964EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A557F460F4E89A33B027385838BDA920D65117873FB49B1D4ED59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34351729636A02D1DE92BA7D837D4338C20360523390B63FE0F4512D2261327A0254A68F80D8BA4D6C1D7E09C32AA3244C9CC7808718C0763912D20AD2C31C6AF17C0C08F7987826B9729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojetunDCtJ20KeaIH7Yr6IVQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822EC1478FCC7C43C120159BE07D483599E83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 2/2] sql: ignore \0 in string passed to Lua-function X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: Mergen Imeev Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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 > 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 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