Skip to content

Commit

Permalink
sql: Print column type even if it is NULL
Browse files Browse the repository at this point in the history
Some commands, e.g. EXPLAIN, invokes SEGMENTATION FAULT when being
executed through net.box. It happens due to column type of the
result of this function being NULL. This patch adds checks for
received column type.
  • Loading branch information
ImeevMA committed Nov 21, 2018
1 parent 9a17eb0 commit 29dde03
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/box/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ sql_get_description(struct sqlite3_stmt *stmt, struct obuf *out,
* column_name simply returns them.
*/
assert(name != NULL);
if (type == NULL)
type = "UNKNOWN";
size += mp_sizeof_str(strlen(name));
size += mp_sizeof_str(strlen(type));
char *pos = (char *) obuf_alloc(out, size);
Expand Down
41 changes: 41 additions & 0 deletions test/sql/iproto.result
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,47 @@ cn:execute('drop table test')
cn:close()
---
...
--
-- Some commands, e.g. EXPLAIN, could lead to segfault because it
-- does not send column data type, but looks like DQL. Netbox had
-- been trying to decode type for any DQL.
--
cn = remote.connect(box.cfg.listen)
---
...
-- Segmentation fault when EXPLAIN executed using net.box.
_ = cn:execute("EXPLAIN SELECT 1;")
---
...
-- Segmentation fault when PRAGMA TABLE_INFO() executed using
-- net.box.
box.sql.execute('CREATE TABLE test (id INT PRIMARY KEY)')
---
...
cn:execute("PRAGMA TABLE_INFO(test);")
---
- metadata:
- name: cid
type: UNKNOWN
- name: name
type: UNKNOWN
- name: type
type: UNKNOWN
- name: notnull
type: UNKNOWN
- name: dflt_value
type: UNKNOWN
- name: pk
type: UNKNOWN
rows:
- [0, 'ID', 'integer', 1, null, 1]
...
box.sql.execute('DROP TABLE test')
---
...
cn:close()
---
...
box.schema.user.revoke('guest', 'read,write,execute', 'universe')
---
...
Expand Down
19 changes: 18 additions & 1 deletion test/sql/iproto.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,27 @@ cn:execute('drop table test')

cn:close()

--
-- Some commands, e.g. EXPLAIN, could lead to segfault because it
-- does not send column data type, but looks like DQL. Netbox had
-- been trying to decode type for any DQL.
--
cn = remote.connect(box.cfg.listen)

-- Segmentation fault when EXPLAIN executed using net.box.
_ = cn:execute("EXPLAIN SELECT 1;")

-- Segmentation fault when PRAGMA TABLE_INFO() executed using
-- net.box.
box.sql.execute('CREATE TABLE test (id INT PRIMARY KEY)')
cn:execute("PRAGMA TABLE_INFO(test);")
box.sql.execute('DROP TABLE test')

cn:close()

box.schema.user.revoke('guest', 'read,write,execute', 'universe')
box.schema.user.revoke('guest', 'create', 'space')
space = nil

-- Cleanup xlog
box.snapshot()

0 comments on commit 29dde03

Please sign in to comment.