Skip to content
Snippets Groups Projects
Commit b99ac0b4 authored by Mergen Imeev's avatar Mergen Imeev Committed by Kirill Yukhin
Browse files

sql: fix assert when MP_EXT received via netbox

This patch fixes an assertion or segmentation fault when getting the
value of MP_EXT via netbox.

Closes #6766

NO_DOC=Bugfix
parent c463e56b
No related branches found
No related tags found
No related merge requests found
## bugfix/sql
* Fixed assertion or segfault when MP_EXT received via net.box (gh-6766).
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
#include "sql/sqlInt.h" #include "sql/sqlInt.h"
#include "sql/sqlLimit.h" #include "sql/sqlLimit.h"
#include "sql/vdbe.h" #include "sql/vdbe.h"
#include "mp_datetime.h"
#include "mp_decimal.h"
#include "mp_uuid.h"
const char * const char *
sql_bind_name(const struct sql_bind *bind) sql_bind_name(const struct sql_bind *bind)
...@@ -99,9 +102,41 @@ sql_bind_decode(struct sql_bind *bind, int i, const char **packet) ...@@ -99,9 +102,41 @@ sql_bind_decode(struct sql_bind *bind, int i, const char **packet)
case MP_BIN: case MP_BIN:
bind->s = mp_decode_bin(packet, &bind->bytes); bind->s = mp_decode_bin(packet, &bind->bytes);
break; break;
case MP_EXT: {
int8_t ext_type;
uint32_t size = mp_decode_extl(packet, &ext_type);
switch (ext_type) {
case MP_UUID:
if (uuid_unpack(packet, size, &bind->uuid) == NULL) {
diag_set(ClientError, ER_INVALID_MSGPACK,
"Invalid MP_UUID MsgPack format");
return -1;
}
break;
case MP_DECIMAL:
if (decimal_unpack(packet, size, &bind->dec) == NULL) {
diag_set(ClientError, ER_INVALID_MSGPACK,
"Invalid MP_DECIMAL MsgPack format");
return -1;
}
break;
case MP_DATETIME:
if (datetime_unpack(packet, size, &bind->dt) == NULL) {
diag_set(ClientError, ER_INVALID_MSGPACK,
"Invalid MP_DATETIME MsgPack format");
return -1;
}
break;
default:
diag_set(ClientError, ER_SQL_BIND_TYPE, "USERDATA",
sql_bind_name(bind));
return -1;
}
bind->ext_type = ext_type;
break;
}
case MP_ARRAY: case MP_ARRAY:
case MP_MAP: case MP_MAP:
case MP_EXT:
bind->s = *packet; bind->s = *packet;
mp_next(packet); mp_next(packet);
bind->bytes = *packet - bind->s; bind->bytes = *packet - bind->s;
......
local server = require('test.luatest_helpers.server')
local t = require('luatest')
local g = t.group()
g.before_all(function()
g.server = server:new({alias = 'gh-6766'})
g.server:start()
end)
g.after_all(function()
g.server:stop()
end)
g.test_6766_1 = function()
local conn = g.server.net_box
local val = require('uuid').new()
local res = {{'uuid'}}
local rows = conn:execute([[SELECT typeof(?);]], {val}).rows
t.assert_equals(rows, res)
end
g.test_6766_2 = function()
local conn = g.server.net_box
local val = require('decimal').new(1.5)
local res = {{'decimal'}}
local rows = conn:execute([[SELECT typeof(?);]], {val}).rows
t.assert_equals(rows, res)
end
g.test_6766_3 = function()
local conn = g.server.net_box
local val = require('datetime').now()
local res = {{'datetime'}}
local rows = conn:execute([[SELECT typeof(?);]], {val}).rows
t.assert_equals(rows, res)
end
g.test_6766_4 = function()
local conn = g.server.net_box
local val = require('msgpack').object_from_raw('\xc7\x00\x0f')
local res = "Bind value type USERDATA for parameter 1 is not supported"
local _, err = pcall(conn.execute, conn, [[SELECT typeof(?);]], {val})
t.assert_equals(err.message, res)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment