[Tarantool-patches] [PATCH 2/2] msgpack: fix wrong mp_ext type in error message
Sergey Kaplun
skaplun at tarantool.org
Mon Jun 15 18:56:18 MSK 2020
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.h> /* lua_*() */
+#include <lauxlib.h> /* luaL_*() */
+#include <lualib.h> /* luaL_openlibs() */
+#include <string.h> /* 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
More information about the Tarantool-patches
mailing list