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 E99EE7F62A; Fri, 6 Aug 2021 22:54:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E99EE7F62A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628279654; bh=ZGRIcXEaAqWy91PWGka6PC4ug5gUgHahMDxpXzkJOmk=; 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=SG9PGZbEakUP/fZ7KeCK2gpOx6HmcBm4s180Skgw4RqG/S9BA54spEd7jNh4Dvhtl /bebpQQf0l+mUKN3gOccLiHqMx2cYB3EBzNVK41TZSQvBqgQWpttPiXpPiZ/Wt0yVE 7BHPhxnt03v9tpVRA6cq1TBpJcbSLdakHA0x8nx8= Received: from smtp41.i.mail.ru (smtp41.i.mail.ru [94.100.177.101]) (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 A106B7F62A for ; Fri, 6 Aug 2021 22:54:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A106B7F62A Received: by smtp41.i.mail.ru with esmtpa (envelope-from ) id 1mC5v1-0008PR-Tb; Fri, 06 Aug 2021 22:54:12 +0300 Date: Fri, 6 Aug 2021 22:54:10 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210806195410.GE11107@tarantool.org> References: <9addd684c79a460bbf20970f88e056cb18492465.1628081224.git.imeevma@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD910164DC12A5633065676A9727AC27C74182A05F5380850402A111F4651A254CBF122D750ECB911D5004B9A36396046CE9EFC6D521065FBC8 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AE0F15972A9DD0A8EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006376F978168E59B07A5EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2E1BAAC3CDAA0BD1FBD9353C5C1107CBECC7F00164DA146DAFE8445B8C89999728AA50765F7900637F6B57BC7E64490618DEB871D839B7333395957E7521B51C2DFABB839C843B9C08941B15DA834481F8AA50765F7900637F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C251EFD5447B32ED603F1AB874ED890284AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C310DC912F9124C96EBA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE798228CBAD4AC77F6731C566533BA786AA5CC5B56E945C8DA X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79D94463893BF8742D0415DECA5814B4B61 X-C1DE0DAB: 0D63561A33F958A5B3AC86A817F04D67DA5E9496D96A06AD48EB0B19F8FA9D94D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75AF0B556A5A327A45410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D344FDECC3B9E4D57D4331364945BA63F12B3E4EA01F71D588ACCC27F7ED7029AD69FB5B77EA5CE91E11D7E09C32AA3244CD41134855C714D23D81512AB9FA051C35A1673A01BA68E40729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojFhlvmGwdUwRY6eegnaaXUQ== X-Mailru-Sender: 3A338A78718AEC5A7171F149183FF3A7EAAC2C73233035587E980F6CF5F08AC9BC1100D5F4C73689A3E7B4BFDCAD2EFE027D9DD7AE851095A2E8D17B49942DB0CBEE3F9BE14373499437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 5/6] alter: disallow creation of SQL built-in 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" Thank you for the review! My answers, diff and new patch below. On Fri, Aug 06, 2021 at 12:18:22AM +0200, Vladislav Shpilevoy wrote: > Thanks for the patch! > > > diff --git a/src/box/alter.cc b/src/box/alter.cc > > index 217b882ba..fd9921ae0 100644 > > --- a/src/box/alter.cc > > +++ b/src/box/alter.cc > > @@ -3213,6 +3213,36 @@ on_replace_dd_user(struct trigger * /* trigger */, void *event) > > return 0; > > } > > > > +/** > > + * Check if the version of the data dictionary is lower than 2.9.0 and return > > + * new func def if it is the case. If it is the case, then it is possible to > > + * insert values with the "SQL_BUILTIN" language into _func, otherwise it is > > + * prohibited. This is for upgradeability from 2.1.3 to 2.3.0. Since all we need > > + * is to allow such inserts, we set func def to its default values. > > + */ > > +static int > > +func_def_new_sql_built_in(struct func_def *def) > > 1. 'new' stands for new memory allocation. Here you need to use > 'create'. > Fixed. > > +{ > > + if (dd_version_id >= version_id(2, 9, 0)) { > > + diag_set(ClientError, ER_FUNCTION_LANGUAGE, "SQL_BUILTIN", > > + def->name); > > + return -1; > > + } > > + def->body = NULL; > > + def->comment = NULL; > > + def->setuid = 1; > > + def->is_deterministic = false; > > + def->is_sandboxed = false; > > + def->param_count = 0; > > + def->returns = FIELD_TYPE_ANY; > > + def->aggregate = FUNC_AGGREGATE_NONE; > > + def->language = FUNC_LANGUAGE_LUA; > > + def->exports.lua = true; > > + def->exports.sql = true; > > + func_opts_create(&def->opts); > > + return 0; > > +} > > + > > /** > > * Get function identifiers from a tuple. > > * > > @@ -3344,6 +3374,14 @@ func_def_new_from_tuple(struct tuple *tuple) > > language, def->name); > > return NULL; > > } > > + if (def->language == FUNC_LANGUAGE_SQL_BUILTIN) { > > 2. Is it possible to just skip such functions when the schema is old? > Simply not create anything for them assuming that they will be deleted > right afterwards. Not even store them in the func hash. Like they do > not exist. Then you can also drop sql_builtin support from > func_def_check(). It is possible to not create new functions, but in this case inserting into _priv will result in an error or assertion (see #6295). In any case, the upgrade will fail. Also, I change the language in def to LUA, so there really is no problem dropping support for sql_builtin from func_def_check(). I did it in the next patch. Diff: diff --git a/src/box/alter.cc b/src/box/alter.cc index fd9921ae0..8a4f0b5a6 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -3221,7 +3221,7 @@ on_replace_dd_user(struct trigger * /* trigger */, void *event) * is to allow such inserts, we set func def to its default values. */ static int -func_def_new_sql_built_in(struct func_def *def) +func_def_create_sql_built_in(struct func_def *def) { if (dd_version_id >= version_id(2, 9, 0)) { diag_set(ClientError, ER_FUNCTION_LANGUAGE, "SQL_BUILTIN", @@ -3375,7 +3375,7 @@ func_def_new_from_tuple(struct tuple *tuple) return NULL; } if (def->language == FUNC_LANGUAGE_SQL_BUILTIN) { - if (func_def_new_sql_built_in(def) != 0) + if (func_def_create_sql_built_in(def) != 0) return NULL; if (func_def_check(def) != 0) return NULL; New patch: commit f0551d7cd7fe5e776fefebb74d0b2f36dac6ca48 Author: Mergen Imeev Date: Wed Aug 4 11:18:46 2021 +0300 alter: disallow creation of SQL built-in function This patch prohibits creation of user-defined functions with SQL_BUILTIN engine. Closes #6106 diff --git a/src/box/alter.cc b/src/box/alter.cc index 217b882ba..8a4f0b5a6 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -3213,6 +3213,36 @@ on_replace_dd_user(struct trigger * /* trigger */, void *event) return 0; } +/** + * Check if the version of the data dictionary is lower than 2.9.0 and return + * new func def if it is the case. If it is the case, then it is possible to + * insert values with the "SQL_BUILTIN" language into _func, otherwise it is + * prohibited. This is for upgradeability from 2.1.3 to 2.3.0. Since all we need + * is to allow such inserts, we set func def to its default values. + */ +static int +func_def_create_sql_built_in(struct func_def *def) +{ + if (dd_version_id >= version_id(2, 9, 0)) { + diag_set(ClientError, ER_FUNCTION_LANGUAGE, "SQL_BUILTIN", + def->name); + return -1; + } + def->body = NULL; + def->comment = NULL; + def->setuid = 1; + def->is_deterministic = false; + def->is_sandboxed = false; + def->param_count = 0; + def->returns = FIELD_TYPE_ANY; + def->aggregate = FUNC_AGGREGATE_NONE; + def->language = FUNC_LANGUAGE_LUA; + def->exports.lua = true; + def->exports.sql = true; + func_opts_create(&def->opts); + return 0; +} + /** * Get function identifiers from a tuple. * @@ -3344,6 +3374,14 @@ func_def_new_from_tuple(struct tuple *tuple) language, def->name); return NULL; } + if (def->language == FUNC_LANGUAGE_SQL_BUILTIN) { + if (func_def_create_sql_built_in(def) != 0) + return NULL; + if (func_def_check(def) != 0) + return NULL; + def_guard.is_active = false; + return def; + } } else { /* Lua is the default. */ def->language = FUNC_LANGUAGE_LUA; diff --git a/test/box/function1.result b/test/box/function1.result index a49a133f7..a1c89850d 100644 --- a/test/box/function1.result +++ b/test/box/function1.result @@ -372,7 +372,7 @@ c:close() box.schema.func.create('WAITFOR', {language = 'SQL_BUILTIN', \ param_list = {'integer'}, returns = 'integer',exports = {'SQL'}}) --- -- error: 'Failed to create function ''WAITFOR'': given built-in is not predefined' +- error: Unsupported language 'SQL_BUILTIN' specified for function 'WAITFOR' ... test_run:cmd("setopt delimiter ';'") --- @@ -1078,3 +1078,8 @@ box.func['test'].is_multikey == true box.func['test']:drop() --- ... +-- gh-6106: Check that user-defined functions cannot have SQL_BUILTIN engine. +box.schema.func.create("ABS", {language = 'SQL_BUILTIN', returns = 'integer'}) +--- +- error: Unsupported language 'SQL_BUILTIN' specified for function 'ABS' +... diff --git a/test/box/function1.test.lua b/test/box/function1.test.lua index 4fdd48520..e635b6e18 100644 --- a/test/box/function1.test.lua +++ b/test/box/function1.test.lua @@ -389,3 +389,6 @@ box.func.LUA:call({"return 1 + 1"}) box.schema.func.create('test', {body = "function(tuple) return tuple end", is_deterministic = true, opts = {is_multikey = true}}) box.func['test'].is_multikey == true box.func['test']:drop() + +-- gh-6106: Check that user-defined functions cannot have SQL_BUILTIN engine. +box.schema.func.create("ABS", {language = 'SQL_BUILTIN', returns = 'integer'})