Tarantool development patches archive
 help / color / mirror / Atom feed
From: imeevma@tarantool.org
To: tarantool-patches@freelists.org, v.shpilevoy@tarantool.org
Subject: [tarantool-patches] [PATCH v1 05/10] sql: EXPLAIN through net.box leads to SEGFAULT
Date: Sat, 17 Nov 2018 17:03:59 +0300	[thread overview]
Message-ID: <34beb94882c75ea855c4af523427e12d8a90c92b.1542460773.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1542460773.git.imeevma@gmail.com>

EXPLAIN envokes SEGMENTATION FAULT when being executed through
net.box. It happens due to column type of the result of this
function being NULL.

Needed for #3505
---
 src/box/execute.c        | 11 +++++++----
 src/box/lua/net_box.c    | 15 ++++++++-------
 test/sql/iproto.result   | 11 +++++++++++
 test/sql/iproto.test.lua |  9 ++++++++-
 4 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/src/box/execute.c b/src/box/execute.c
index 80ad655..da2f09c 100644
--- a/src/box/execute.c
+++ b/src/box/execute.c
@@ -468,15 +468,18 @@ sql_get_description(struct sqlite3_stmt *stmt, struct vstream *stream,
 		 * column_name simply returns them.
 		 */
 		assert(name != NULL);
-		vstream_encode_map(stream, 2);
+		int map_size = (type == NULL) ? 1 : 2;
+		vstream_encode_map(stream, map_size);
 
 		vstream_encode_enum(stream, IPROTO_FIELD_NAME, "name");
 		vstream_encode_str(stream, name);
 		vstream_encode_map_commit(stream);
 
-		vstream_encode_enum(stream, IPROTO_FIELD_TYPE, "type");
-		vstream_encode_str(stream, type);
-		vstream_encode_map_commit(stream);
+		if (map_size == 2) {
+			vstream_encode_enum(stream, IPROTO_FIELD_TYPE, "type");
+			vstream_encode_str(stream, type);
+			vstream_encode_map_commit(stream);
+		}
 
 		vstream_encode_array_commit(stream, i);
 	}
diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c
index c7063d9..342c6a7 100644
--- a/src/box/lua/net_box.c
+++ b/src/box/lua/net_box.c
@@ -644,8 +644,7 @@ netbox_decode_metadata(struct lua_State *L, const char **data)
 	lua_createtable(L, count, 0);
 	for (uint32_t i = 0; i < count; ++i) {
 		uint32_t map_size = mp_decode_map(data);
-		assert(map_size == 2);
-		(void) map_size;
+		assert(map_size == 1 || map_size == 2);
 		uint32_t key = mp_decode_uint(data);
 		assert(key == IPROTO_FIELD_NAME);
 		(void) key;
@@ -654,11 +653,13 @@ netbox_decode_metadata(struct lua_State *L, const char **data)
 		const char *str = mp_decode_str(data, &len);
 		lua_pushlstring(L, str, len);
 		lua_setfield(L, -2, "name");
-		key = mp_decode_uint(data);
-		assert(key == IPROTO_FIELD_TYPE);
-		const char *type = mp_decode_str(data, &len);
-		lua_pushlstring(L, type, len);
-		lua_setfield(L, -2, "type");
+		if (map_size == 2) {
+			key = mp_decode_uint(data);
+			assert(key == IPROTO_FIELD_TYPE);
+			const char *type = mp_decode_str(data, &len);
+			lua_pushlstring(L, type, len);
+			lua_setfield(L, -2, "type");
+		}
 		lua_rawseti(L, -2, i + 1);
 	}
 }
diff --git a/test/sql/iproto.result b/test/sql/iproto.result
index d077ee8..0571a3b 100644
--- a/test/sql/iproto.result
+++ b/test/sql/iproto.result
@@ -773,6 +773,17 @@ cn:execute('drop table test')
 cn:close()
 ---
 ...
+-- gh-3505: Remove box.sql.execute
+cn = remote.connect(box.cfg.listen)
+---
+...
+-- Segmentation fault when EXPLAIN executed using net.box.
+_ = cn:execute("EXPLAIN SELECT 1;")
+---
+...
+cn:close()
+---
+...
 box.schema.user.revoke('guest', 'read,write,execute', 'universe')
 ---
 ...
diff --git a/test/sql/iproto.test.lua b/test/sql/iproto.test.lua
index 1470eda..e708bb2 100644
--- a/test/sql/iproto.test.lua
+++ b/test/sql/iproto.test.lua
@@ -247,10 +247,17 @@ cn:execute('drop table test')
 
 cn:close()
 
+-- gh-3505: Remove box.sql.execute
+cn = remote.connect(box.cfg.listen)
+
+-- Segmentation fault when EXPLAIN executed using net.box.
+_ = cn:execute("EXPLAIN SELECT 1;")
+
+cn:close()
+
 box.schema.user.revoke('guest', 'read,write,execute', 'universe')
 box.schema.user.revoke('guest', 'create', 'space')
 space = nil
 
 -- Cleanup xlog
 box.snapshot()
-
-- 
2.7.4

  parent reply	other threads:[~2018-11-17 14:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-17 14:03 [tarantool-patches] [PATCH v1 00/10] sql: remove box.sql.execute imeevma
2018-11-17 14:03 ` [tarantool-patches] [PATCH v1 01/10] box: store sql text and length in sql_request imeevma
2018-11-17 14:03 ` [tarantool-patches] [PATCH v1 02/10] iproto: remove iproto functions from execute.c imeevma
2018-11-19 17:58   ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-17 14:03 ` [tarantool-patches] [PATCH v1 03/10] iproto: replace obuf by mpstream in execute.c imeevma
2018-11-17 14:03 ` [tarantool-patches] [PATCH v1 04/10] sql: create interface vstream imeevma
2018-11-19 17:58   ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-17 14:03 ` imeevma [this message]
2018-11-19 13:47   ` [tarantool-patches] Re: [PATCH v1 05/10] sql: EXPLAIN through net.box leads to SEGFAULT Vladislav Shpilevoy
2018-11-17 14:04 ` [tarantool-patches] [PATCH v1 06/10] sql: SELECT from system spaces returns unpacked msgpack imeevma
2018-11-19 13:48   ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-17 14:04 ` [tarantool-patches] [PATCH v1 07/10] sql: too many autogenerated ids leads to SEGFAULT imeevma
2018-11-19 13:47   ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-17 14:04 ` [tarantool-patches] [PATCH v1 08/10] box: add method dump_lua to port imeevma
2018-11-17 14:04 ` [tarantool-patches] [PATCH v1 09/10] lua: create vstream implementation for Lua imeevma
2018-11-19 17:58   ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-17 14:04 ` [tarantool-patches] [PATCH v1 10/10] sql: check new box.sql.execute() imeevma
2018-11-19 12:54 ` [tarantool-patches] Re: [PATCH v1 00/10] sql: remove box.sql.execute Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=34beb94882c75ea855c4af523427e12d8a90c92b.1542460773.git.imeevma@gmail.com \
    --to=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH v1 05/10] sql: EXPLAIN through net.box leads to SEGFAULT' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox