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 E88EE6EC55; Thu, 9 Sep 2021 14:07:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E88EE6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1631185678; bh=0r9+6JzkuGjYGXfGC74otSmic0UfWJ/n4HDNI+GycCc=; 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=Xr42k0uJ8VEFNhzciPgqTYy7pAXUTJ1OYnP7jGh5RkYVhaLFJlXVKBSBG8RyiPMC4 OLeNX4Ke5CO57oA3Ee+4jKz3dBLCIcRlKFwYLt3x6n4qxljJVwM42/fSG0IK27/S3c CVtnypfLRjs5sEkhnVAHau5gzmg1h9pd3/gbMkPY= 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 C470D6EC55 for ; Thu, 9 Sep 2021 14:07:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C470D6EC55 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mOHuN-0007Nx-T0; Thu, 09 Sep 2021 14:07:56 +0300 Date: Thu, 9 Sep 2021 14:07:54 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210909110754.GA51222@tarantool.org> References: <38ac1b8d1ecae3352b8fe748def9e8a451239b9a.1630915850.git.imeevma@gmail.com> <4e091d79-84c5-9ba1-f624-185cfced6591@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <4e091d79-84c5-9ba1-f624-185cfced6591@tarantool.org> X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD91AE02D33A9C88A2FD33F16D892CA5215E5B7E73120F3783D00894C459B0CD1B90E6437C1170200507C5FC676D808367376EBFC5E065C261968897FC172A4A22D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE741DC22BF90A736D8EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063703E3935C5A8197E98638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D88ABEC9C4115445D41EB05CB0851D5D73117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B3733B5EC72352B9FA471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C565C1E6824D8037B43847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A53401F816B16246015CB1C3F926720E11210DE6CF746ED828D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75E3127721F5A72C97410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D343FB425EC7F4D4A4B7A8B775C0566316D27E38D934473CF1C4F5D2E883464FC1D3A98E057BEF5E1941D7E09C32AA3244CA0F7B85B62F9D2CE2B56C99E47C03CE8B038C9161EF167A1729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojV8xpaxME9p8ekhzyPni4xg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D3FBAD592D9AB8614D5D617B8247A6ACF83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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! My answers, diff and new patch below. On Tue, Sep 07, 2021 at 11:59:58PM +0200, Vladislav Shpilevoy wrote: > Hi! Thanks for the patch! > > See 4 comments below. > > On 06.09.2021 10:11, imeevma@tarantool.org wrote: > > Prior to this patch, an assertion was throwed if a tuple with an > > 1. throwed -> thrown. > Fixed. > > 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 > > 2. Could you please add a changelog? > Added. > > 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") > > 3. Shouldn't the message be like a comment? Describing the correct > behaviour. It is printed always along with ok/no ok in the tap output. > So it should be about what is expected. > Thanks, fixed. > > 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 > > 4. Why? The test does not pass in release? > It does, however in release build nothing will change. At least at the first glance. > > config = suite.cfg > > fragile = { > > "retries": 10, > > Diff: diff --git a/changelogs/unreleased/gh-6295-assert-on-wrong-insert-into-_priv.md b/changelogs/unreleased/gh-6295-assert-on-wrong-insert-into-_priv.md new file mode 100644 index 000000000..058d218d7 --- /dev/null +++ b/changelogs/unreleased/gh-6295-assert-on-wrong-insert-into-_priv.md @@ -0,0 +1,5 @@ +## bugfix/sql + +* Now inserting a tuple with the wrong "id" field into the \_priv space will + return the correct error (gh-6295). + 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 index e4822f395..add2df429 100755 --- a/test/box-tap/gh-6295-assert-on-wrong-id.test.lua +++ b/test/box-tap/gh-6295-assert-on-wrong-id.test.lua @@ -13,22 +13,22 @@ box.cfg{} 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") +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Proper error is returned") 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") +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Proper error is returned") 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") +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Proper error is returned") 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") +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Proper error is returned") 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") +test:is_deeply({ok, tostring(res)}, {false, errmsg}, "Proper error is returned") os.exit(test:check() and 0 or 1) diff --git a/test/box-tap/suite.ini b/test/box-tap/suite.ini index fd55d5d24..b09d7db4f 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, gh-6295-assert-on-wrong-id.test.lua +release_disabled = errinj_set_with_enviroment_vars.test.lua config = suite.cfg fragile = { "retries": 10, New patch: commit a3542e0082c480f166796281d3996f6edfffcaf7 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 thrown if a tuple with an invalid id was inserted into the _priv system space. This bug appeared only in the debug build. Closes #6295 diff --git a/changelogs/unreleased/gh-6295-assert-on-wrong-insert-into-_priv.md b/changelogs/unreleased/gh-6295-assert-on-wrong-insert-into-_priv.md new file mode 100644 index 000000000..058d218d7 --- /dev/null +++ b/changelogs/unreleased/gh-6295-assert-on-wrong-insert-into-_priv.md @@ -0,0 +1,5 @@ +## bugfix/sql + +* Now inserting a tuple with the wrong "id" field into the \_priv space will + return the correct error (gh-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..add2df429 --- /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}, "Proper error is returned") + +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}, "Proper error is returned") + +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}, "Proper error is returned") + +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}, "Proper error is returned") + +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}, "Proper error is returned") + +os.exit(test:check() and 0 or 1)