From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 235E56EC55; Wed, 28 Jul 2021 00:24:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 235E56EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627421088; bh=JlnqKJhhpB4eefUc0nePiLTrmsSWCxWaFL0w9a7Guxw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=VVy0ajgOa7lCTqsO/n1qiQo4k+iTOBTDIhi6g3Fx0esxfzZfwO69PRh1GAc4tH7Dg cAAa5lqS1vwdt17plY6NbdHfRCy+m4sj5jZYl1J3Wj/dBAD2cuDq5QOGJQmLmks4rj c3v6Xpz3FkuswV+f1IXMej9M/1x/Vz6fDn9f9RtY= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [94.100.177.149]) (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 844536EC55 for ; Wed, 28 Jul 2021 00:24:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 844536EC55 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1m8UYj-0005in-Hb; Wed, 28 Jul 2021 00:24:17 +0300 To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergos@tarantool.org Date: Tue, 27 Jul 2021 23:24:11 +0200 Message-Id: <0104ef1d3f256b7e062806b5a29fe42525ec1b77.1627420835.git.v.shpilevoy@tarantool.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C3038391AAE5FBFA7682283CBB09BF492D182A05F538085040938DDAB592C6204BDD5FBBB67E060CD98D2FDC3FA57CCAD2386EE8D68A9CB369 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7C2204D4F9A221771EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637C21C2889FA5309238638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8BF3E2B82B87C83C547E301326AC705C4117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF80095D1E57F4578A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BDCE939D40DBB93CA75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505E2552B0CE6D9DCA41288C59D8F606168 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7BEA09003D200E0899C39E00428B8542E19DD28272435D839C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFA5DF9383870C0FED699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D349320586B19AD2C72C5A4BC2F6C8F459C0BD885AA370DA04416F4D16419C59C60220F77BA55D1BD371D7E09C32AA3244C9F2C3838DA4D975FC95B61BFD90D33B95A1673A01BA68E40FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojiF1u9eOpfTS8287bAz0IPQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DFA5B9043481321D655D08363C362A42A3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 1/5] uuid: introduce and use luaL_pushuuidstr() X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" The function safely pushes tt_uuid as a string on a Lua stack. Safety means that it does not use tt_uuid_str() which stores the result into the global static buffer and can not be used in Lua context. The static buffer is not safe to use in Lua and Lua C because during a static string push onto a Lua stack the GC might be started and it can spoil the buffer. Part of #6259 --- src/box/lua/net_box.c | 4 +--- src/lua/utils.c | 13 +++++++++++++ src/lua/utils.h | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c index 3f43872ca..d1c7bedf6 100644 --- a/src/box/lua/net_box.c +++ b/src/box/lua/net_box.c @@ -422,7 +422,6 @@ netbox_decode_greeting(lua_State *L) struct greeting greeting; size_t len; const char *buf = NULL; - char uuid_buf[UUID_STR_LEN + 1]; if (lua_isstring(L, 1)) buf = lua_tolstring(L, 1, &len); @@ -443,8 +442,7 @@ netbox_decode_greeting(lua_State *L) lua_pushlstring(L, greeting.salt, greeting.salt_len); lua_setfield(L, -2, "salt"); - tt_uuid_to_string(&greeting.uuid, uuid_buf); - lua_pushstring(L, uuid_buf); + luaL_pushuuidstr(L, &greeting.uuid); lua_setfield(L, -2, "uuid"); return 1; diff --git a/src/lua/utils.c b/src/lua/utils.c index 34cec0eed..bcd647827 100644 --- a/src/lua/utils.c +++ b/src/lua/utils.c @@ -37,6 +37,7 @@ #include #include #include +#include "uuid/tt_uuid.h" int luaL_nil_ref = LUA_REFNIL; @@ -107,6 +108,18 @@ luaL_pushuuid(struct lua_State *L) return luaL_pushcdata(L, CTID_UUID); } +void +luaL_pushuuidstr(struct lua_State *L, const struct tt_uuid *uuid) +{ + /* + * Do not use a global buffer. It might be overwritten if GC starts + * working. + */ + char str[UUID_STR_LEN + 1]; + tt_uuid_to_string(uuid, str); + lua_pushlstring(L, str, UUID_STR_LEN); +} + int luaL_iscdata(struct lua_State *L, int idx) { diff --git a/src/lua/utils.h b/src/lua/utils.h index 947d9240b..804fc9548 100644 --- a/src/lua/utils.h +++ b/src/lua/utils.h @@ -73,6 +73,9 @@ extern uint32_t CTID_UUID; struct tt_uuid * luaL_pushuuid(struct lua_State *L); +void +luaL_pushuuidstr(struct lua_State *L, const struct tt_uuid *uuid); + /** \cond public */ /** -- 2.24.3 (Apple Git-128)