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 BDD926EC5B; Tue, 30 Mar 2021 14:22:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BDD926EC5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617103344; bh=/mRESmFI2cNJBaM/od3/FN/BBNd641753lSboevf+hU=; 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=OqAe6hi7Th1DjEry75q0CyVv3wCuFoAlspheKIiUfwT1CxM7te3LjkNiCl7D6Gzc5 abNXW8K14ypF1F/r4fb/z7y4FSKOREkDuHSRgV5I6XVz54tTPyKgnxs4WBbzL52mAy pMgIxtcBTYOWhTe4+4peww/7WKN7bH9B+cadXidI= Received: from smtp43.i.mail.ru (smtp43.i.mail.ru [94.100.177.103]) (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 EE0526FC8B for ; Tue, 30 Mar 2021 14:21:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EE0526FC8B Received: by smtp43.i.mail.ru with esmtpa (envelope-from ) id 1lRCRV-0001bU-9d; Tue, 30 Mar 2021 14:21:53 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 30 Mar 2021 14:21:53 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9ED7173E37F4E329498ADEA61F680B110809A4DE3E6FC56EA182A05F5380850408B1BFE6EE8F8E2FF417E338D6C45E512CDDEA13E2A41B86808075491B561E24D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D3E352D4AD7EBF54EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637539FDAA91738A5BD8638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95CE99938B3FD79E1DFCF216B6265875D0ECC3F6F212973D4B2A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE71AE4D56B06699BBC9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C317B107DEF921CE79117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF72CC1424E84F783DBA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6EC0BC6DB5D5D7B8B3AA81AA40904B5D9DBF02ECDB25306B2201CA6A4E26CD07C3BBE47FD9DD3FB595F5C1EE8F4F765FCA83251EDC214901ED5E8D9A59859A8B69C803D8CAE72B18A089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46D0DA44B1EEEB204B4355D89D7DBCDD132 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CE99938B3FD79E1DFCF216B6265875D0ECC3F6F212973D4B29C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C2E47CA9A560609012E58FEC1926140EF0231CD0D72B15350CC50433C5F4B7B53084956B4E09C8FE1D7E09C32AA3244CB6AE87BCB449FE9CAA95B3CD30E9710AD9ADFF0C0BDB8D1F729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXhvv95JXCZNDjwAmI0xy/YW X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED7E736119522AE337417E338D6C45E512C9F871340C5A6C405105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 1/2] sql: ignore \0 in string passed to C-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 C-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. Now it isn't cropped when passed from SQL. Part of #5938 --- src/box/sql/func.c | 3 +- test/CMakeLists.txt | 1 + test/sql-tap/CMakeLists.txt | 2 + test/sql-tap/gh-5938-wrong-string-length.c | 42 +++++++++++++++++++ .../gh-5938-wrong-string-length.test.lua | 28 +++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/sql-tap/CMakeLists.txt create mode 100644 test/sql-tap/gh-5938-wrong-string-length.c create mode 100755 test/sql-tap/gh-5938-wrong-string-length.test.lua diff --git a/src/box/sql/func.c b/src/box/sql/func.c index f15d27051..c3c14bd22 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -175,7 +175,8 @@ port_vdbemem_get_msgpack(struct port *base, uint32_t *size) } case MP_STR: { const char *str = (const char *) sql_value_text(param); - mpstream_encode_str(&stream, str); + mpstream_encode_strn(&stream, str, + sql_value_bytes(param)); break; } case MP_BIN: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7fe078835..7276996d9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -62,6 +62,7 @@ add_subdirectory(app) add_subdirectory(app-tap) add_subdirectory(box) add_subdirectory(box-tap) +add_subdirectory(sql-tap) if(ENABLE_FUZZER) add_subdirectory(fuzz) endif() diff --git a/test/sql-tap/CMakeLists.txt b/test/sql-tap/CMakeLists.txt new file mode 100644 index 000000000..6e2eae2ff --- /dev/null +++ b/test/sql-tap/CMakeLists.txt @@ -0,0 +1,2 @@ +include_directories(${MSGPUCK_INCLUDE_DIRS}) +build_module(gh-5938-wrong-string-length gh-5938-wrong-string-length.c) diff --git a/test/sql-tap/gh-5938-wrong-string-length.c b/test/sql-tap/gh-5938-wrong-string-length.c new file mode 100644 index 000000000..96823f049 --- /dev/null +++ b/test/sql-tap/gh-5938-wrong-string-length.c @@ -0,0 +1,42 @@ +#include +#include "module.h" + +enum +{ + BUF_SIZE = 512, +}; + +int +ret_str(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + uint32_t arg_count = mp_decode_array(&args); + if (arg_count != 1) { + return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", + "invalid argument count"); + } + if (mp_typeof(*args) != MP_STR) { + return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", + "argument should be string"); + } + const char* str; + uint32_t str_n; + str = mp_decode_str(&args, &str_n); + + uint32_t size = mp_sizeof_array(1) + mp_sizeof_str(str_n); + if (size > BUF_SIZE) { + return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", + "string is too long"); + } + + char tuple_buf[BUF_SIZE]; + char *d = tuple_buf; + d = mp_encode_array(d, 1); + d = mp_encode_str(d, str, str_n); + assert(d <= tuple_buf + size); + + box_tuple_format_t *fmt = box_tuple_format_default(); + box_tuple_t *tuple = box_tuple_new(fmt, tuple_buf, d); + if (tuple == NULL) + return -1; + return box_return_tuple(ctx, tuple); +} diff --git a/test/sql-tap/gh-5938-wrong-string-length.test.lua b/test/sql-tap/gh-5938-wrong-string-length.test.lua new file mode 100755 index 000000000..943389e34 --- /dev/null +++ b/test/sql-tap/gh-5938-wrong-string-length.test.lua @@ -0,0 +1,28 @@ +#!/usr/bin/env tarantool +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) + +box.schema.func.create("gh-5938-wrong-string-length.ret_str", { + language = "C", + param_list = { "string" }, + returns = "string", + exports = { "LUA", "SQL" }, + is_deterministic = true +}) + +test:execsql([[CREATE TABLE t (i INT PRIMARY KEY, s STRING);]]) +box.space.T:insert({1, 'This is a complete string'}) +box.space.T:insert({2, 'This is a cropped\0 string'}) + +test:do_execsql_test( + "gh-5938-1", + [[ + SELECT "gh-5938-wrong-string-length.ret_str"(s) from t; + ]], { + "This is a complete string","This is a cropped\0 string" + }) + +test:finish_test() -- 2.25.1