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 E1DDB6EC40; Fri, 4 Jun 2021 13:40:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E1DDB6EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1622803213; bh=f36sCbI2VY67gqyig3rnBghaQIs7rlM5umN6A6tuNLg=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=srEGlAUl2Rk6nDQdIONYl2zng/fxeOm8kuBZ53iM8rIJpAiB/0XS9rymbl8H08cFj +twyDg3+bb20bA3WSHuSsusPUwgIU6uzMHEg+IP45xwMyELTeTMZ+KxI1O05GDqW10 CwKeLjZLOD56LZGtO4cPu4MXJWtqz71M1gRVao8g= Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [217.69.128.34]) (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 EBCA56EC40 for ; Fri, 4 Jun 2021 13:40:11 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EBCA56EC40 Received: by smtp54.i.mail.ru with esmtpa (envelope-from ) id 1lp7FL-0005i0-33; Fri, 04 Jun 2021 13:40:11 +0300 To: Mergen Imeev Cc: tarantool-patches@dev.tarantool.org References: <4fef21459158c16b993e0f72db337674129834df.1622735576.git.imeevma@gmail.com> <3e5643e5-1b53-e012-5f66-9e0e152a14f5@tarantool.org> <20210604102317.GA30691@tarantool.org> Message-ID: Date: Fri, 4 Jun 2021 13:40:10 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <20210604102317.GA30691@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D5B0DA836B685C54907A7AE9C1BA82BC67C1327DFB87C6A6182A05F53808504004848E78D3A383134DA0ED68F2879BC9872183CD072E094198EFB2A4FB0A1C8E X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE700B5EAEB6F2DE1BDEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374A24022C550661178638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8A147DA7CB2967B74BB56BCDE605F0912117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD186FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EED76C6ED7039589DE4D0DA9BD313A0613D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE34AB4081B6A6C2E076136E347CC761E07C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637FB177F6A8366F17BEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A5053FB2B1F7BC2FD026FBE52C049AE43B6B63B7133017CFB8D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75FBC5FED0552DA851410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D346C409ABC5F9C579B50F1C28A2D3A933C65A94CD43C67671864FB73A198F2C9C16AA0849EEFDA6C9B1D7E09C32AA3244C5DBA5FC271A3501A1B9DC8B993E020AF6C24832127668422729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojz99asgmzejqOG/6U9AkmHQ== X-Mailru-Sender: 583F1D7ACE8F49BD9DF7A8DAE6E2B08A0C87AEC9F802237D2F69C4990CFBD8655BE98B5A3CA3905C424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 1/1] box: check STRING length when it is cast to UUID 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: Serge Petrenko via Tarantool-patches Reply-To: Serge Petrenko Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 04.06.2021 13:23, Mergen Imeev пишет: > Hi! Thank you for the review! My answer, diff and new patch below. Thanks for the fix! LGTM. > > On Fri, Jun 04, 2021 at 12:57:34PM +0300, Serge Petrenko wrote: >> >> 03.06.2021 18:54, imeevma@tarantool.org пишет: >>> After this patch, the tt_uuid_from_strl() function will check the length >>> of the given string before converting it to a UUID. >>> >>> Follow up #5886 >> Hi! Thanks for the patch! >> Please, find one comment below. >> >>> --- >>> https://github.com/tarantool/tarantool/issues/5886 >>> https://github.com/tarantool/tarantool/tree/imeevma/gh-5886-follow-up >>> >>> src/lib/uuid/tt_uuid.c | 2 ++ >>> test/sql-tap/uuid.test.lua | 19 ++++++++++++++++++- >>> 2 files changed, 20 insertions(+), 1 deletion(-) >>> >>> diff --git a/src/lib/uuid/tt_uuid.c b/src/lib/uuid/tt_uuid.c >>> index 8bc9bc7af..6bdf2014a 100644 >>> --- a/src/lib/uuid/tt_uuid.c >>> +++ b/src/lib/uuid/tt_uuid.c >>> @@ -98,6 +98,8 @@ tt_uuid_str(const struct tt_uuid *uu) >>> int >>> tt_uuid_from_strl(const char *in, size_t len, struct tt_uuid *uu) >>> { >>> + if (len != UUID_STR_LEN) >>> + return -1; >> tt_uuid_from_string() returns '1' in case of an error, so let's stay >> consistent here. >> > Thanks, fixed. > >>> char buf[UUID_STR_LEN + 1]; >>> snprintf(buf, sizeof(buf), "%.*s", (int) len, in); >>> return tt_uuid_from_string(buf, uu); >>> diff --git a/test/sql-tap/uuid.test.lua b/test/sql-tap/uuid.test.lua >>> index 83fcc3d0e..77ba06c2d 100755 >>> --- a/test/sql-tap/uuid.test.lua >>> +++ b/test/sql-tap/uuid.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(145) >>> +test:plan(147) >>> local uuid = require("uuid") >>> local uuid1 = uuid.fromstr("11111111-1111-1111-1111-111111111111") >>> @@ -1316,6 +1316,23 @@ test:do_execsql_test( >>> true >>> }) >>> +-- Make sure STRING of wrong length cannot be cast to UUID. >>> +test:do_catchsql_test( >>> + "uuid-17.1", >>> + [[ >>> + SELECT CAST('11111111-1111-1111-1111-111111111111111222222222' AS UUID); >>> + ]], { >>> + 1, "Type mismatch: can not convert 11111111-1111-1111-1111-111111111111111222222222 to uuid" >>> + }) >>> + >>> +test:do_catchsql_test( >>> + "uuid-17.2", >>> + [[ >>> + SELECT CAST('11111111-1111-1111-1111-11111' AS UUID); >>> + ]], { >>> + 1, "Type mismatch: can not convert 11111111-1111-1111-1111-11111 to uuid" >>> + }) >>> + >>> test:execsql([[ >>> DROP TRIGGER t; >>> DROP VIEW v; >> -- >> Serge Petrenko >> > > Diff: > > diff --git a/src/lib/uuid/tt_uuid.c b/src/lib/uuid/tt_uuid.c > index 6bdf2014a..d92376650 100644 > --- a/src/lib/uuid/tt_uuid.c > +++ b/src/lib/uuid/tt_uuid.c > @@ -99,7 +99,7 @@ int > tt_uuid_from_strl(const char *in, size_t len, struct tt_uuid *uu) > { > if (len != UUID_STR_LEN) > - return -1; > + return 1; > char buf[UUID_STR_LEN + 1]; > snprintf(buf, sizeof(buf), "%.*s", (int) len, in); > return tt_uuid_from_string(buf, uu); > > Patch: > > commit 914c02c99c616bef3d5ff87306c79a7921dfeec7 > Author: Mergen Imeev > Date: Thu Jun 3 15:41:03 2021 +0300 > > box: check STRING length when it is cast to UUID > > After this patch, the tt_uuid_from_strl() function will check the length > of the given string before converting it to a UUID. > > Follow up #5886 > > diff --git a/src/lib/uuid/tt_uuid.c b/src/lib/uuid/tt_uuid.c > index 8bc9bc7af..d92376650 100644 > --- a/src/lib/uuid/tt_uuid.c > +++ b/src/lib/uuid/tt_uuid.c > @@ -98,6 +98,8 @@ tt_uuid_str(const struct tt_uuid *uu) > int > tt_uuid_from_strl(const char *in, size_t len, struct tt_uuid *uu) > { > + if (len != UUID_STR_LEN) > + return 1; > char buf[UUID_STR_LEN + 1]; > snprintf(buf, sizeof(buf), "%.*s", (int) len, in); > return tt_uuid_from_string(buf, uu); > diff --git a/test/sql-tap/uuid.test.lua b/test/sql-tap/uuid.test.lua > index 83fcc3d0e..77ba06c2d 100755 > --- a/test/sql-tap/uuid.test.lua > +++ b/test/sql-tap/uuid.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(145) > +test:plan(147) > > local uuid = require("uuid") > local uuid1 = uuid.fromstr("11111111-1111-1111-1111-111111111111") > @@ -1316,6 +1316,23 @@ test:do_execsql_test( > true > }) > > +-- Make sure STRING of wrong length cannot be cast to UUID. > +test:do_catchsql_test( > + "uuid-17.1", > + [[ > + SELECT CAST('11111111-1111-1111-1111-111111111111111222222222' AS UUID); > + ]], { > + 1, "Type mismatch: can not convert 11111111-1111-1111-1111-111111111111111222222222 to uuid" > + }) > + > +test:do_catchsql_test( > + "uuid-17.2", > + [[ > + SELECT CAST('11111111-1111-1111-1111-11111' AS UUID); > + ]], { > + 1, "Type mismatch: can not convert 11111111-1111-1111-1111-11111 to uuid" > + }) > + > test:execsql([[ > DROP TRIGGER t; > DROP VIEW v; -- Serge Petrenko