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 A1FE942EF5E for ; Mon, 15 Jun 2020 18:56:36 +0300 (MSK) From: Sergey Kaplun Date: Mon, 15 Jun 2020 18:56:18 +0300 Message-Id: <9e6b2ec973a0dd0f2bb6da4915bf1f8f7ff58081.1592235478.git.skaplun@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2/2] msgpack: fix wrong mp_ext type in error message List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org Cc: Alexander Turenko This patch adds decoding of mp_ext type and inserts it into error message when an error is raised Closes #5017 --- src/lua/msgpack.c | 5 +++-- test/unit/CMakeLists.txt | 5 +++++ test/unit/mplua.c | 47 ++++++++++++++++++++++++++++++++++++++++ test/unit/mplua.result | 5 +++++ 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 test/unit/mplua.c create mode 100644 test/unit/mplua.result diff --git a/src/lua/msgpack.c b/src/lua/msgpack.c index b7a2955fe..e3935d383 100644 --- a/src/lua/msgpack.c +++ b/src/lua/msgpack.c @@ -224,8 +224,9 @@ luamp_set_encode_extension(luamp_encode_extension_f handler) static void luamp_decode_extension_default(struct lua_State *L, const char **data) { - luaL_error(L, "msgpack.decode: unsupported extension: %u", - (unsigned char) **data); + int8_t ext_type; + mp_decode_extl(data, &ext_type); + luaL_error(L, "msgpack.decode: unsupported extension: %u", ext_type); } diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 6dfb10f46..906422e82 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -205,3 +205,8 @@ target_link_libraries(coll.test core unit ${ICU_LIBRARIES} misc) add_executable(tuple_bigref.test tuple_bigref.c) target_link_libraries(tuple_bigref.test tuple unit) + +add_executable(mplua.test mplua.c) +target_link_libraries(mplua.test unit box server core + ${CURL_LIBRARIES} ${LIBYAML_LIBRARIES} ${READLINE_LIBRARIES} + ${ICU_LIBRARIES} ${LUAJIT_LIBRARIES}) diff --git a/test/unit/mplua.c b/test/unit/mplua.c new file mode 100644 index 000000000..3b7f4de76 --- /dev/null +++ b/test/unit/mplua.c @@ -0,0 +1,47 @@ +#include /* lua_*() */ +#include /* luaL_*() */ +#include /* luaL_openlibs() */ +#include /* memcmp() */ + +#include "lua/msgpack.h" +#include "unit.h" + +/* + * test for https://github.com/tarantool/tarantool/issues/5017 + */ + + +static int +lua_encode_unknown_mp(struct lua_State *L) +{ + const char test_str[] = "\xd4\x0f\x00"; + const char *data = (char *)test_str; + luamp_decode(L, luaL_msgpack_default, &data); + return 0; +} + + +static void +test_luamp_encode_extension_default(struct lua_State *L) +{ + plan(2); + lua_pushcfunction(L, lua_encode_unknown_mp); + ok(lua_pcall(L, 0, 0, 0) != 0, + "mplua_decode: unsupported extension raise error"); + const char err_msg[] = "msgpack.decode: unsupported extension: 15"; + ok(memcmp(lua_tostring(L, -1), err_msg, sizeof(err_msg)) == 0, + "mplua_decode: unsupported extension correct type"); +} + + +int +main(void) +{ + header(); + + struct lua_State *L = luaL_newstate(); + test_luamp_encode_extension_default(L); + + footer(); + check_plan(); +} diff --git a/test/unit/mplua.result b/test/unit/mplua.result new file mode 100644 index 000000000..6dc9d2ee3 --- /dev/null +++ b/test/unit/mplua.result @@ -0,0 +1,5 @@ + *** main *** +1..2 +ok 1 - mplua_decode: unsupported extension raise error +ok 2 - mplua_decode: unsupported extension correct type + *** main: done *** -- 2.24.1