From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [217.69.128.43]) (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 ED8B442EF5C for ; Fri, 3 Jul 2020 16:32:58 +0300 (MSK) From: Ilya Kosarev Date: Fri, 3 Jul 2020 16:32:55 +0300 Message-Id: <20200703133255.23820-1-i.kosarev@tarantool.org> Subject: [Tarantool-patches] [PATCH] engine: validate key in space_before_replace List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org Cc: v.shpilevoy@tarantool.org Since 9fba29abb4e05babb9b23b4413bd8083f0fba933 (memtx: introduce tuple compare hint) index_get uses key_hint to get a comparison hint for the key. It requires key type to be validated. However in space_before_replace index_get was used without key validation on some execution paths. Now it is fixed and validation is being performed if needed. Corresponding test case is introduced. Closes #5093 --- Branch: https://github.com/tarantool/tarantool/tree/i.kosarev/gh-5093-before_replace-key-validation Issue: https://github.com/tarantool/tarantool/issues/5093 @ChangeLog: * Add needed key validation to space_before_replace. src/box/space.c | 6 +++--- .../gh-5093-before_replace-key-type.result | 21 +++++++++++++++++++ .../gh-5093-before_replace-key-type.test.lua | 7 +++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 test/engine/gh-5093-before_replace-key-type.result create mode 100644 test/engine/gh-5093-before_replace-key-type.test.lua diff --git a/src/box/space.c b/src/box/space.c index eecbde7fa7..66768208b3 100644 --- a/src/box/space.c +++ b/src/box/space.c @@ -359,9 +359,6 @@ space_before_replace(struct space *space, struct txn *txn, return -1; key = request->key; part_count = mp_decode_array(&key); - if (exact_key_validate(index->def->key_def, - key, part_count) != 0) - return -1; break; case IPROTO_INSERT: case IPROTO_REPLACE: @@ -380,6 +377,9 @@ space_before_replace(struct space *space, struct txn *txn, /* Unknown request type, nothing to do. */ return 0; } + if (key != NULL && + exact_key_validate(index->def->key_def, key, part_count) != 0) + return -1; struct tuple *old_tuple = NULL; if (index != NULL && diff --git a/test/engine/gh-5093-before_replace-key-type.result b/test/engine/gh-5093-before_replace-key-type.result new file mode 100644 index 0000000000..abf5b2c194 --- /dev/null +++ b/test/engine/gh-5093-before_replace-key-type.result @@ -0,0 +1,21 @@ +-- test-run result file version 2 +test_run = require('test_run').new() + | --- + | ... +trigger = function() end + | --- + | ... + +s = box.schema.space.create('gh-5093', {engine=test_run:get_cfg('engine')}) + | --- + | ... +_ = s:create_index('value', {parts={{1, type='decimal'}}}) + | --- + | ... +_ = s:before_replace(trigger) + | --- + | ... +s:replace{'1111.1111'} + | --- + | - error: 'Supplied key type of part 0 does not match index part type: expected decimal' + | ... diff --git a/test/engine/gh-5093-before_replace-key-type.test.lua b/test/engine/gh-5093-before_replace-key-type.test.lua new file mode 100644 index 0000000000..9cba3c1597 --- /dev/null +++ b/test/engine/gh-5093-before_replace-key-type.test.lua @@ -0,0 +1,7 @@ +test_run = require('test_run').new() +trigger = function() end + +s = box.schema.space.create('gh-5093', {engine=test_run:get_cfg('engine')}) +_ = s:create_index('value', {parts={{1, type='decimal'}}}) +_ = s:before_replace(trigger) +s:replace{'1111.1111'} -- 2.17.1