Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun <skaplun@tarantool.org>
To: tarantool-patches@dev.tarantool.org
Cc: Alexander Turenko <alexander.turenko@tarantool.org>
Subject: [Tarantool-patches] [PATCH 2/2] msgpack: fix wrong mp_ext type in error message
Date: Mon, 15 Jun 2020 18:56:18 +0300	[thread overview]
Message-ID: <9e6b2ec973a0dd0f2bb6da4915bf1f8f7ff58081.1592235478.git.skaplun@tarantool.org> (raw)
In-Reply-To: <cover.1592235478.git.skaplun@tarantool.org>

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

  parent reply	other threads:[~2020-06-15 15:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15 15:56 [Tarantool-patches] [PATCH 0/2] Msgpack wrong extension " Sergey Kaplun
2020-06-15 15:56 ` [Tarantool-patches] [PATCH 1/2] lib: update msgpuck library Sergey Kaplun
2020-06-15 15:56 ` Sergey Kaplun [this message]
2020-07-14 15:46   ` [Tarantool-patches] [PATCH 2/2] msgpack: fix wrong mp_ext type in error message Igor Munkin
2020-07-15  9:32     ` Sergey Kaplun
2020-07-15 15:21       ` Sergey Kaplun
2020-07-16 20:53       ` Igor Munkin
2020-07-17  8:35         ` Sergey Kaplun
2020-07-17  9:09           ` Alexander Turenko
2020-07-17  9:54             ` Sergey Kaplun
2020-07-17  9:23           ` sergos
2020-07-17 10:12           ` Igor Munkin
2020-07-17 11:02             ` Sergey Kaplun
2020-07-17 11:27 ` [Tarantool-patches] [PATCH 0/2] Msgpack wrong extension " Kirill Yukhin

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=9e6b2ec973a0dd0f2bb6da4915bf1f8f7ff58081.1592235478.git.skaplun@tarantool.org \
    --to=skaplun@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 2/2] msgpack: fix wrong mp_ext type in error message' \
    /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