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 39D946EC40; Fri, 4 Jun 2021 13:23:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 39D946EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1622802201; bh=Hm/QvriYJII+SncIImSTzK0JKZ84l+4QagRkUWmTlkM=; 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=CYMeZLJgT+c1yr9Zs6vEHtMA9EkXGRl/oqfqlc1Q/r7v+Y/9DiXKBx786/qnUannS WqHs459SBdJYTPrgu2j5QQDKO5X4aBiXc7B4TuwSt4VedVxAl/rcf+q5pIdh2S7bpM C9IdLMt/A/C9/R78Qm7NDU6g6KyLp6/SEd6Yhnks= Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 CBBEA6EC40 for ; Fri, 4 Jun 2021 13:23:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CBBEA6EC40 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1lp6z0-0002dE-Vb; Fri, 04 Jun 2021 13:23:19 +0300 Date: Fri, 4 Jun 2021 13:23:17 +0300 To: Serge Petrenko Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210604102317.GA30691@tarantool.org> References: <4fef21459158c16b993e0f72db337674129834df.1622735576.git.imeevma@gmail.com> <3e5643e5-1b53-e012-5f66-9e0e152a14f5@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3e5643e5-1b53-e012-5f66-9e0e152a14f5@tarantool.org> X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D5B0DA836B685C54F4BC37E91F2690B85F43D7652182C513182A05F5380850408ADF6929453DE1AEB7FBBEE0D7B6304FBADC95E7A9340C267B430D67B8271282 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE757AEC41D7AA04458EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637FD169B9D7A3022168638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81F226D61BFEFC50DFB149AEE2FC9F64D117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5E910F46383D47C4E6C7CAD9E5ECAE15BF4ECFE66A1FFECDDD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75FBC5FED0552DA851410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D341C998A3771F04153C59E332AC2CD34CDAF7594CCD8055E4329E7DDEF56EA1B3FDA8AEA59254107D41D7E09C32AA3244CF2A273DB7B707BC74AAB7CBDE008C4495A1673A01BA68E40729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojz99asgmzejqQoY+B9Nd+BQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822C348DB71DE5A9341C1DAF78DEC3176E083D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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: 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 answer, diff and new patch below. 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;