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 B21AB6EC5D; Fri, 2 Apr 2021 01:50:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B21AB6EC5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617317412; bh=RfeH4EHqfoQiZq9ufAFsV2mMG3C/PgrX2qqui9ThsOw=; 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=ZFQHmjH1DmQPLOZGoO9/XBxVM8tICkX697PErBs9nliszIKhU96TOH/t1q0+ZczqZ +ibx6LmJuC6xQlrCiao2mt5suyUUwxU2XRmuulsSZiFHNjpmBSeV+JtPdAYQsbU3Fg mtGW9g3E8GKrx23ycL5dBDQhXXdpcPJqo3B2mceE= Received: from smtp35.i.mail.ru (smtp35.i.mail.ru [94.100.177.95]) (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 23C0E6EC5D for ; Fri, 2 Apr 2021 01:50:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 23C0E6EC5D Received: by smtp35.i.mail.ru with esmtpa (envelope-from ) id 1lS68h-0006We-H9; Fri, 02 Apr 2021 01:50:11 +0300 Date: Fri, 2 Apr 2021 01:50:10 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210401225010.GA7318@tarantool.org> References: <446a9874ec7289914571b7989a194939747d46a7.1617101707.git.imeevma@gmail.com> <20210401084102.GA54278@tarantool.org> <1da9dba4-2c42-d827-3f61-c30910ff7a1b@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1da9dba4-2c42-d827-3f61-c30910ff7a1b@tarantool.org> X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9ED7173E37F4E3294DD38BE31D7797EF84C856624A09E4809182A05F538085040A191AC8A1E42191900058C98D8EF4B62D416C52ED70E54DEA05FF60799BACBBB X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7922E451CE6E839B1EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377EC9BDDC32C0C0498638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C7B5A45DDF210A4CF08F335C73F89437A800A1546E72A582FA471835C12D1D9774AD6D5ED66289B5259CC434672EE6371117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE71AE4D56B06699BBC9FA2833FD35BB23DF004C90652538430302FCEF25BFAB3454AD6D5ED66289B5278DA827A17800CE7D267E580484B939ED32BA5DBAC0009BE395957E7521B51C20BC6067A898B09E4090A508E0FED6299176DF2183F8FC7C0598443F9A192C740CD04E86FAF290E2D7E9C4E3C761E06A71DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B693D5B6784794C261089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824AC8B6CDF511875BC4E8F7B195E1C97831EE1B2BD425336DAFEE3E100BA2433E01 X-C1DE0DAB: 0D63561A33F958A519D3A2E209D2E5BDBC2AF5E86FAEDBEB291D9FD7D934561AD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A08F09726D78E07BA3C1C3B5C17925A5EC8DF22ADE71A602C65DA75170202B7F29633C4014E0AB681D7E09C32AA3244C2A1B610C9851C152A3DD22EB18BA196F5595C85A795C7BAE729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojiysexgWf33422/0UkZ0Zyw== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED1BD7DE559391A35D00058C98D8EF4B626CCF71F689FD47EE5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 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" 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 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()