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 5D96C6EC5B; Tue, 30 Mar 2021 14:22:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5D96C6EC5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617103373; bh=Fxe7lg5Y59DmHZ6bzRYwW8lsY5gPyGW2BPTD5HGcJMI=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=dDmizsuB1nzfZk/9AnaNO8W8cDsvQdZXNhLUziIT+phHWmgR03qc6w7fuILxxof8n PkvhD3+tj3OfAaweI5+DebYXL3EG31ZWY3Ooa5Z4ynuKfE6jb8Z7TWbk/q4GY8V5ov tCMnB23mZWDn4tC/nlzf/XsbS8dWvvmek/H/BKt4= Received: from smtp37.i.mail.ru (smtp37.i.mail.ru [94.100.177.97]) (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 EF80D6FFA1 for ; Tue, 30 Mar 2021 14:21:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EF80D6FFA1 Received: by smtp37.i.mail.ru with esmtpa (envelope-from ) id 1lRCRX-0004yW-9y; Tue, 30 Mar 2021 14:21:55 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 30 Mar 2021 14:21:55 +0300 Message-Id: <446a9874ec7289914571b7989a194939747d46a7.1617101707.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9ED7173E37F4E3294CA3588DDE0233B0D17711AF1EA2D7DB9182A05F538085040365FB2D913DDB9119ADFB9965C233C9CC292EEB9F9B6652E6F28D91B0A48E7D9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE752E71F0C64B7C834EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637DA223B75F41C64628638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95CE99938B3FD79E1DF7D0F07302C02938F1BAFB81BED14DF85A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE71AE4D56B06699BBC9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3ED8438A78DFE0A9E117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF450179847B4E9FFDBA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6F7EC8CC465A83DA33AA81AA40904B5D9DBF02ECDB25306B2201CA6A4E26CD07C3BBE47FD9DD3FB595F5C1EE8F4F765FCA83251EDC214901ED5E8D9A59859A8B6753C3A5E0A5AB5B7089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CE99938B3FD79E1DF7D0F07302C02938F1BAFB81BED14DF859C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C2E47CA9A560609066BBA8570CBB83895844A8D96EEBFA17A61BE9487616B935BAD6B264490F65AD1D7E09C32AA3244CA7BB6DA77C497488EC47EC4CCEBF4642D08D48398F32B4A6729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXhvv95JXCZNDnmF9Y3I3dcb X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306EDD02A511AFE30D1D49ADFB9965C233C9C0D95629463F16A6A5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [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: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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