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 17CCF6EC55; Mon, 6 Sep 2021 11:11:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 17CCF6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1630915908; bh=Cusksjkf3iSXHbmyDIOxBmsrdW0OPeO11CEB/3vpb+8=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=sFrEUTEKI9NFDL7ReYlYnx+2XEa8737/XzbozOOjkdUAYwK63N4eYNpPpKAbsPq2e PkSiT0FKhEZeM5DCFTiwNWrQwmvdHiqJ8rCIbeKPWE5qnPZJ8HqVRESgzDdF+RVjqA VNcheWqHnW4cD7P7ZxOaDqp3dIRs/3d5cuuVDtsA= 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 177E86EC55 for ; Mon, 6 Sep 2021 11:11:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 177E86EC55 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mN9jG-0008MT-6e; Mon, 06 Sep 2021 11:11:46 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Mon, 6 Sep 2021 11:11:45 +0300 Message-Id: <38ac1b8d1ecae3352b8fe748def9e8a451239b9a.1630915850.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D96C1EA41D18F4D57B705481ADDDE748772430255B74E284182A05F5380850405E86CC4E5D391B2D59A934FF347F11492462AA7157433226306667AA12036D3A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE76DD23B0452F84E3CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CDE631A26C8A2C128638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8004C5F4C3D55DA054B88303A5CA92EFE117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735209ECD01F8117BC8BEA471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C565C1E6824D8037B43847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C3E385859ED5ED7564DA789B05B98C9C7CFE37C0DB19B32639C2B6934AE262D3EE7EAB7254005DCEDE285C580305385EE1E0A4E2319210D9B64D260DF9561598F01A9E91200F654B0CCA28C6D779E2CD78E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34524B2D44961BF9C60E8A2E52F58A09672F8616AD3AC9668C1D713CFB19AE2592DB7404C8E3569A031D7E09C32AA3244C9C835F44A37B0DBA4481F716C3CB2C38A995755A1445935E729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXiPA8u9Wk+QmfTn5EiiYN2z X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D8BA9354AD4E65C016D52B34DCC37467283D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [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: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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/alter.cc | 2 + src/box/schema.cc | 47 ++++++++++++------- .../gh-6295-assert-on-wrong-id.test.lua | 34 ++++++++++++++ test/box-tap/suite.ini | 2 +- 4 files changed, 68 insertions(+), 17 deletions(-) create mode 100755 test/box-tap/gh-6295-assert-on-wrong-id.test.lua 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, -- 2.25.1