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 DFFA46EC55; Mon, 6 Sep 2021 11:05:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DFFA46EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1630915519; bh=F7wrch+lWQ9eVzNtU9J6kubfbCBk9GtacpqWo1QTYg0=; 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=yP8XXAO3SdnnnDK+soRNo0K+xrI31l/rC2mUgYPgBtGHE9ZJqWqARZpWezKENjtEU 5xVrw9ucHw0T89OF0EWIFeE+EeKpikqEgzN7HTZrZkPDrC/ChAW81zhgLZ+Nq13n+d qMS46ObCt9gCqpdWjwL3AdnIS7BizVzf7jbMHACE= Received: from smtp16.mail.ru (smtp16.mail.ru [94.100.176.153]) (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 ADC176EC55 for ; Mon, 6 Sep 2021 11:05:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org ADC176EC55 Received: by smtp16.mail.ru with esmtpa (envelope-from ) id 1mN9cy-0000B8-Kt; Mon, 06 Sep 2021 11:05:17 +0300 To: Mergen Imeev Cc: tarantool-patches@dev.tarantool.org References: <20210903065931.GA38349@tarantool.org> Message-ID: <699a8180-f3be-2c3d-5ba5-a3246ccd0ecd@tarantool.org> Date: Mon, 6 Sep 2021 11:05:16 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210903065931.GA38349@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9D96C1EA41D18F4D502C758EA1710EDB6F5A7A0628E11ABA6182A05F538085040C72B4C321924D3F569ADD84984366B67CAE69398795A5A5FB0C15D36B0E2450E X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D77100FFB2844417EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E78B284398E2029E8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D80764FF57C55D5DB2FA5D093362B0CC6C117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEC65AC60A1F0286FEE2071C6999E77799D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE38ED1AC82D843A2BB9735652A29929C6CC4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F79006373BA04B6A498D0BA4731C566533BA786AA5CC5B56E945C8DA X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B5051CB43F2A4F91C3F798D1D30E50F00998 X-C1DE0DAB: 0D63561A33F958A561FD631B7BF28C6B882DDF6AE4B82880B628B167E3E756D2D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA752546FE575EB473F1410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3475AE8838CC1BF58EE6F21FFC280AF44EA0E85E3827C2452A27BF98DB03E87C0CC61630FB9EC7CB311D7E09C32AA3244C812DCE318A3B144FDFBEF52764232D00BBA718C7E6A9E042729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj2BdsxQzaueXFywVI4ihagg== X-Mailru-Sender: 583F1D7ACE8F49BD31DE23046B3A846085105D97292B6CF0726775C2DF211638219434EAC0284D466BB2E709EA627F343C7DDD459B58856F0E45BC603594F5A135B915D4279FF0579437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 1/1] schema: remove assert on wrong insert into _priv 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" 03.09.2021 09:59, Mergen Imeev пишет: > Hi! Thank you for the review! And sorry for such late reply. My answer, diff and > new patch below. > > On Tue, Aug 17, 2021 at 03:32:02PM +0300, Serge Petrenko wrote: >> >> 16.08.2021 19:13, imeevma@tarantool.org пишет: >>> Prior to this patch, an assertion was throwed if a tuple with an >>> incorrect id was inserted into the _priv system space. This bug >>> appeared only in the debug build. >>> >>> Closes #6295 >>> --- >>> https://github.com/tarantool/tarantool/issues/6295 >>> https://github.com/tarantool/tarantool/tree/imeevma/gh-6295-assert-on-insert-with-wrong-id >>> >>> src/box/schema.cc | 1 - >>> .../gh-6295-assert-on-wrong-id.test.lua | 34 +++++++++++++++++++ >>> test/box-tap/suite.ini | 2 +- >>> 3 files changed, 35 insertions(+), 2 deletions(-) >>> create mode 100755 test/box-tap/gh-6295-assert-on-wrong-id.test.lua >>> >>> diff --git a/src/box/schema.cc b/src/box/schema.cc >>> index 1970871cc..ac19a2b1e 100644 >>> --- a/src/box/schema.cc >>> +++ b/src/box/schema.cc >>> @@ -730,7 +730,6 @@ schema_find_name(enum schema_object_type type, uint32_t object_id) >>> default: >>> break; >>> } >>> - assert(false); >>> return "(nil)"; >>> } >> >> Thanks for the patch! >> >> I think it's better to return NULL in this case. >> And set the diagnostics accordingly. >> And check for schema_find_name results in alter.cc >> >> schema_find_name is the place where we already know there's no such space, >> or >> function, and so on. >> >> So priv_def_check should fail right at schema_find_name, not later. >> > Fixed. > >>> diff --git a/test/box-tap/gh-6295-assert-on-wrong-id.test.lua b/test/box-tap/gh-6295-assert-on-wrong-id.test.lua >>> new file mode 100755 >>> index 000000000..e4822f395 >>> --- /dev/null >>> +++ b/test/box-tap/gh-6295-assert-on-wrong-id.test.lua >>> @@ -0,0 +1,34 @@ >>> +#!/usr/bin/env tarantool >>> + >>> +local tap = require('tap') >>> +local test = tap.test('gh-6295-assert-on-wrong-id') >>> + >>> +test:plan(5) >>> + >>> +local ok, res >>> + >>> +box.cfg{} >>> + >>> +-- Should be an error, not an assertion. >>> +local _priv = box.space._priv >>> +local errmsg = "Function '1000000' does not exist" >>> +ok, res = pcall(_priv.replace, _priv, {1, 2, 'function', 1000000, box.priv.A}) >>> +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Function exists") >>> + >>> +errmsg = "Sequence '1000000' does not exist" >>> +ok, res = pcall(_priv.replace, _priv, {1, 2, 'sequence', 1000000, box.priv.A}) >>> +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Sequence exists") >>> + >>> +errmsg = "Space '1000000' does not exist" >>> +ok, res = pcall(_priv.replace, _priv, {1, 2, 'space', 1000000, box.priv.A}) >>> +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Space exists") >>> + >>> +errmsg = "User '1000000' is not found" >>> +ok, res = pcall(_priv.replace, _priv, {1, 2, 'user', 1000000, box.priv.A}) >>> +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "User exists") >>> + >>> +errmsg = "Role '1000000' is not found" >>> +ok, res = pcall(_priv.replace, _priv, {1, 2, 'role', 1000000, box.priv.A}) >>> +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Role exists") >>> + >>> +os.exit(test:check() and 0 or 1) >>> diff --git a/test/box-tap/suite.ini b/test/box-tap/suite.ini >>> index b09d7db4f..fd55d5d24 100644 >>> --- a/test/box-tap/suite.ini >>> +++ b/test/box-tap/suite.ini >>> @@ -3,7 +3,7 @@ core = app >>> description = Database tests with #! using TAP >>> is_parallel = True >>> use_unix_sockets_iproto = True >>> -release_disabled = errinj_set_with_enviroment_vars.test.lua >>> +release_disabled = errinj_set_with_enviroment_vars.test.lua, gh-6295-assert-on-wrong-id.test.lua >>> config = suite.cfg >>> fragile = { >>> "retries": 10, >> -- >> Serge Petrenko >> > > Diff: > > diff --git a/src/box/alter.cc b/src/box/alter.cc > index 3bd56feb9..e87fbb847 100644 > --- a/src/box/alter.cc > +++ b/src/box/alter.cc > @@ -3954,6 +3954,8 @@ priv_def_check(struct priv_def *priv, enum priv_type priv_type) > return -1; > } > const char *name = schema_find_name(priv->object_type, priv->object_id); > + if (name == NULL) > + return -1; > if (access_check_ddl(name, priv->object_id, grantor->def->uid, > priv->object_type, priv_type) != 0) > return -1; > diff --git a/src/box/schema.cc b/src/box/schema.cc > index ac19a2b1e..cf1e531e3 100644 > --- a/src/box/schema.cc > +++ b/src/box/schema.cc > @@ -701,35 +701,51 @@ schema_find_name(enum schema_object_type type, uint32_t object_id) > case SC_SPACE: > { > struct space *space = space_by_id(object_id); > - if (space == NULL) > - break; > - return space->def->name; > + if (space != NULL) > + return space->def->name; > + diag_set(ClientError, ER_NO_SUCH_SPACE, > + tt_sprintf("%d", object_id)); > + break; > } > case SC_FUNCTION: > { > struct func *func = func_by_id(object_id); > - if (func == NULL) > - break; > - return func->def->name; > + if (func != NULL) > + return func->def->name; > + diag_set(ClientError, ER_NO_SUCH_FUNCTION, > + tt_sprintf("%d", object_id)); > + break; > } > case SC_SEQUENCE: > { > struct sequence *seq = sequence_by_id(object_id); > - if (seq == NULL) > - break; > - return seq->def->name; > + if (seq != NULL) > + return seq->def->name; > + diag_set(ClientError, ER_NO_SUCH_SEQUENCE, > + tt_sprintf("%d", object_id)); > + break; > } > case SC_ROLE: > - case SC_USER: > { > struct user *role = user_by_id(object_id); > - if (role == NULL) > - break; > - return role->def->name; > + if (role != NULL) > + return role->def->name; > + diag_set(ClientError, ER_NO_SUCH_ROLE, > + tt_sprintf("%d", object_id)); > + break; > + } > + case SC_USER: > + { > + struct user *user = user_by_id(object_id); > + if (user != NULL) > + return user->def->name; > + diag_set(ClientError, ER_NO_SUCH_USER, > + tt_sprintf("%d", object_id)); > + break; > } > default: > - break; > + unreachable(); > } > - return "(nil)"; > + return NULL; > } > Thanks for the fixes! LGTM. > New patch: > > > commit 38ac1b8d1ecae3352b8fe748def9e8a451239b9a > Author: Mergen Imeev > Date: Sat Aug 7 13:11:12 2021 +0300 > > schema: remove assert on wrong insert into _priv > > Prior to this patch, an assertion was throwed if a tuple with an > incorrect id was inserted into the _priv system space. This bug > appeared only in the debug build. > > Closes #6295 > > diff --git a/src/box/alter.cc b/src/box/alter.cc > index 3bd56feb9..e87fbb847 100644 > --- a/src/box/alter.cc > +++ b/src/box/alter.cc > @@ -3954,6 +3954,8 @@ priv_def_check(struct priv_def *priv, enum priv_type priv_type) > return -1; > } > const char *name = schema_find_name(priv->object_type, priv->object_id); > + if (name == NULL) > + return -1; > if (access_check_ddl(name, priv->object_id, grantor->def->uid, > priv->object_type, priv_type) != 0) > return -1; > diff --git a/src/box/schema.cc b/src/box/schema.cc > index 1970871cc..cf1e531e3 100644 > --- a/src/box/schema.cc > +++ b/src/box/schema.cc > @@ -701,36 +701,51 @@ schema_find_name(enum schema_object_type type, uint32_t object_id) > case SC_SPACE: > { > struct space *space = space_by_id(object_id); > - if (space == NULL) > - break; > - return space->def->name; > + if (space != NULL) > + return space->def->name; > + diag_set(ClientError, ER_NO_SUCH_SPACE, > + tt_sprintf("%d", object_id)); > + break; > } > case SC_FUNCTION: > { > struct func *func = func_by_id(object_id); > - if (func == NULL) > - break; > - return func->def->name; > + if (func != NULL) > + return func->def->name; > + diag_set(ClientError, ER_NO_SUCH_FUNCTION, > + tt_sprintf("%d", object_id)); > + break; > } > case SC_SEQUENCE: > { > struct sequence *seq = sequence_by_id(object_id); > - if (seq == NULL) > - break; > - return seq->def->name; > + if (seq != NULL) > + return seq->def->name; > + diag_set(ClientError, ER_NO_SUCH_SEQUENCE, > + tt_sprintf("%d", object_id)); > + break; > } > case SC_ROLE: > - case SC_USER: > { > struct user *role = user_by_id(object_id); > - if (role == NULL) > - break; > - return role->def->name; > + if (role != NULL) > + return role->def->name; > + diag_set(ClientError, ER_NO_SUCH_ROLE, > + tt_sprintf("%d", object_id)); > + break; > + } > + case SC_USER: > + { > + struct user *user = user_by_id(object_id); > + if (user != NULL) > + return user->def->name; > + diag_set(ClientError, ER_NO_SUCH_USER, > + tt_sprintf("%d", object_id)); > + break; > } > default: > - break; > + unreachable(); > } > - assert(false); > - return "(nil)"; > + return NULL; > } > > diff --git a/test/box-tap/gh-6295-assert-on-wrong-id.test.lua b/test/box-tap/gh-6295-assert-on-wrong-id.test.lua > new file mode 100755 > index 000000000..e4822f395 > --- /dev/null > +++ b/test/box-tap/gh-6295-assert-on-wrong-id.test.lua > @@ -0,0 +1,34 @@ > +#!/usr/bin/env tarantool > + > +local tap = require('tap') > +local test = tap.test('gh-6295-assert-on-wrong-id') > + > +test:plan(5) > + > +local ok, res > + > +box.cfg{} > + > +-- Should be an error, not an assertion. > +local _priv = box.space._priv > +local errmsg = "Function '1000000' does not exist" > +ok, res = pcall(_priv.replace, _priv, {1, 2, 'function', 1000000, box.priv.A}) > +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Function exists") > + > +errmsg = "Sequence '1000000' does not exist" > +ok, res = pcall(_priv.replace, _priv, {1, 2, 'sequence', 1000000, box.priv.A}) > +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Sequence exists") > + > +errmsg = "Space '1000000' does not exist" > +ok, res = pcall(_priv.replace, _priv, {1, 2, 'space', 1000000, box.priv.A}) > +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Space exists") > + > +errmsg = "User '1000000' is not found" > +ok, res = pcall(_priv.replace, _priv, {1, 2, 'user', 1000000, box.priv.A}) > +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "User exists") > + > +errmsg = "Role '1000000' is not found" > +ok, res = pcall(_priv.replace, _priv, {1, 2, 'role', 1000000, box.priv.A}) > +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Role exists") > + > +os.exit(test:check() and 0 or 1) > diff --git a/test/box-tap/suite.ini b/test/box-tap/suite.ini > index b09d7db4f..fd55d5d24 100644 > --- a/test/box-tap/suite.ini > +++ b/test/box-tap/suite.ini > @@ -3,7 +3,7 @@ core = app > description = Database tests with #! using TAP > is_parallel = True > use_unix_sockets_iproto = True > -release_disabled = errinj_set_with_enviroment_vars.test.lua > +release_disabled = errinj_set_with_enviroment_vars.test.lua, gh-6295-assert-on-wrong-id.test.lua > config = suite.cfg > fragile = { > "retries": 10, -- Serge Petrenko