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 BDC216FC85; Fri, 3 Sep 2021 09:59:35 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BDC216FC85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1630652375; bh=QSceIYCNZ4KAcCpvjhOQ3UxMWNLHEvXqTCti9ONAD40=; 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=WRgxc1ySKqJD/6iko0DY+RiTkFP6ge+2075XTLUIH6W3+BjOklZuXOPAwQk+y77FF 49tipouS7zVeAURKICxXkGNOrk8e4YDhJ61kCfDI5cYrgXHfRRjIjf9M+LiVYneI+6 +nO7bSdQqiBZCPUmJgstEztRQ/18zm7hYEaStHtE= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [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 082B66FC85 for ; Fri, 3 Sep 2021 09:59:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 082B66FC85 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mM3Aj-0003AE-2N; Fri, 03 Sep 2021 09:59:33 +0300 Date: Fri, 3 Sep 2021 09:59:31 +0300 To: Serge Petrenko Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210903065931.GA38349@tarantool.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D96C1EA41D18F4D5B168DC3F7DB30EB4BE25CD3FBE4D8277182A05F538085040FAD55C33E9542F9E48FFCDF9EED5611581529C34EF1C4F587D65C0C91176BA3A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE779AAD18609327F83EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006373BFF7CCD9F2968778638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C897A5E2BDC03076175BE3D67DBBD5DF117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6300D3B61E77C8D3B089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A523C74E902F163E5C660FCF6D17307A1729F372F63A6BA890D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA752546FE575EB473F1410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D348BF433665406F3901606DBE2745AB1B4598DB410267E854477DAB2841B282A2A604CD202F003B7CD1D7E09C32AA3244C1873566E1C8F8FA3024C3A5A648A7E3969B6CAE0477E908D729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioja9FuITQvsRroppij/KapCg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DC202020CE87BD0E2A75D6ED7C059AEFA83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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: 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! 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; } 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,