From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [94.100.177.107]) (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 84C3346970E for ; Mon, 27 Jan 2020 17:04:22 +0300 (MSK) From: Chris Sosnin Date: Mon, 27 Jan 2020 17:04:20 +0300 Message-Id: <20200127140420.52553-1-k.sosnin@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH] sql: fix segfault in pragma table_info List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, tarantool-patches@dev.tarantool.org We should first check that primary key is not NULL. Closes #4745 --- branch: https://github.com/tarantool/tarantool/tree/ksosnin/gh-4745-table-info-assertion issue: https://github.com/tarantool/tarantool/issues/4745 src/box/sql/pragma.c | 6 +++--- test/sql/engine.cfg | 1 + test/sql/gh-4745-table-info-assertion.result | 8 ++++++++ test/sql/gh-4745-table-info-assertion.test.lua | 5 +++++ 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 test/sql/gh-4745-table-info-assertion.result create mode 100644 test/sql/gh-4745-table-info-assertion.test.lua diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c index 636f519ef..a77bf4b16 100644 --- a/src/box/sql/pragma.c +++ b/src/box/sql/pragma.c @@ -112,10 +112,10 @@ sql_pragma_table_info(struct Parse *parse, const char *tbl_name) struct Vdbe *v = sqlGetVdbe(parse); struct field_def *field = space->def->fields; for (uint32_t i = 0, k; i < space->def->field_count; ++i, ++field) { - if (!sql_space_column_is_in_pk(space, i)) { - k = 0; - } else if (pk == NULL) { + if (pk == NULL) { k = 1; + } else if (!sql_space_column_is_in_pk(space, i)) { + k = 0; } else { struct key_def *kdef = pk->def->key_def; k = key_def_find_by_fieldno(kdef, i) - kdef->parts + 1; diff --git a/test/sql/engine.cfg b/test/sql/engine.cfg index 1e9f08c6a..06c761166 100644 --- a/test/sql/engine.cfg +++ b/test/sql/engine.cfg @@ -2,6 +2,7 @@ "vinyl-opts.test.lua" : { "vinyl": {"engine": "vinyl"} }, + "gh-4745-table-info-assertion.test.lua": { }, "bind.test.lua": { "remote": {"remote": "true"}, "local": {"remote": "false"} diff --git a/test/sql/gh-4745-table-info-assertion.result b/test/sql/gh-4745-table-info-assertion.result new file mode 100644 index 000000000..51a75b816 --- /dev/null +++ b/test/sql/gh-4745-table-info-assertion.result @@ -0,0 +1,8 @@ +-- test-run result file version 2 +-- +-- The following pragma shouldn't cause +-- assertion fault +-- +table_info = box.execute('pragma table_info("_vinyl_deferred_delete")') + | --- + | ... diff --git a/test/sql/gh-4745-table-info-assertion.test.lua b/test/sql/gh-4745-table-info-assertion.test.lua new file mode 100644 index 000000000..19d2f6955 --- /dev/null +++ b/test/sql/gh-4745-table-info-assertion.test.lua @@ -0,0 +1,5 @@ +-- +-- The following pragma shouldn't cause +-- assertion fault +-- +table_info = box.execute('pragma table_info("_vinyl_deferred_delete")') -- 2.21.1 (Apple Git-122.3)