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 139206EC60; Thu, 1 Apr 2021 11:41:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 139206EC60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617266465; bh=b5Ei98Ly5XH1Zgi7rWMH+NgLivFrP5CCc5d1R8MWg1s=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=EZgW2VJpVZ7hBe/vjsFSrEpOVnBxUxLX7YXuDoZEaKkrJUFS1bsN1MOBVdclfduqo u2avXRlr87rg9Ldto5z47kkalplMkwRngZZWDyq7KdoRvb7loqP+mN5JtCwi2j3i6p A8kdsy3Q0FtMiLclHkFQmPmqiyG/dyCgfVrccjJw= Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 DD3F86EC60 for ; Thu, 1 Apr 2021 11:41:03 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DD3F86EC60 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1lRssx-0003LI-67; Thu, 01 Apr 2021 11:41:03 +0300 Date: Thu, 1 Apr 2021 11:41:02 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210401084102.GA54278@tarantool.org> References: <446a9874ec7289914571b7989a194939747d46a7.1617101707.git.imeevma@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9ED7173E37F4E32947A0146560F8BA709C5527BBE40F25C64182A05F538085040FBF52AFA6661A66650C60CBC573D37209E7A75118CEB64E21D42C98DB7C93CFA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE72424932217190DC2EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637C3BF94FB392044A18638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95CE99938B3FD79E1DF98F95764E2FB42015B7DF6EFB3EBFA55A471835C12D1D9774AD6D5ED66289B5259CC434672EE6371117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658359CC434672EE6371117882F4460429728AD0CFFFB425014E868A13BD56FB6657E2021AF6380DFAD1A18204E546F3947C0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735E4A630A5B664A4FFC4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5D0143884170325FCFBC8A079171FB9830CEE4000C8F762B2D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D16EA493CC1FD9F8C8FE013215D2C561E1D97CBDDA23F15555BD47D4012F6A7A8ED08192FB6815F51D7E09C32AA3244CD092C13F4635B529DE6C0726BF040C59F94338140B71B8EE729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojetunDCtJ20LvV8czwo+JFg== X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638228FCF2D0F753848900EB348389AC3196883D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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" 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()