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 5B0116EC55; Thu, 29 Jul 2021 14:30:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5B0116EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627558252; bh=oBIp3sgYNPSQCBzZCEekzIivVesTM+2f48P80g7ZEd0=; h=In-Reply-To:Date:References:To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=JKMtYZk+FHk4pEpnsU1es8COlayRQ9QSIB4OrEUPOvImjWS4jhNn/OlFmDfCKr7Ef H2glJ+e41SpgZVC8M+cDzJ9W6LaE8WbrlRxJ/nHhrkjpoD6YUPH+5KLkxSZGB2/ZKz p9408rbQBSPiX32aoIQ5xtYUKumlkTodGmzFFI0w= Received: from smtp55.i.mail.ru (smtp55.i.mail.ru [217.69.128.35]) (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 B35786EC55 for ; Thu, 29 Jul 2021 14:30:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B35786EC55 Received: by smtp55.i.mail.ru with esmtpa (envelope-from ) id 1m94FM-0006Xs-QT; Thu, 29 Jul 2021 14:30:41 +0300 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.100.0.2.22\)) In-Reply-To: <0104ef1d3f256b7e062806b5a29fe42525ec1b77.1627420835.git.v.shpilevoy@tarantool.org> Date: Thu, 29 Jul 2021 14:30:38 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <0104ef1d3f256b7e062806b5a29fe42525ec1b77.1627420835.git.v.shpilevoy@tarantool.org> To: Vladislav Shpilevoy X-Mailer: Apple Mail (2.3654.100.0.2.22) X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C3104FC76DFAAAAF7DA068FE323FAC4379182A05F538085040BE24D429C6AAECDD8C29C5AC14737C9419DEB063A41B90D08445F1AF2624B34D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE712EB008F780777E9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637B6B039AA0E19584A8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D855E621765CB820E6D20CA585628545B1117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD1828451B159A507268D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B60A62CEF541B197C8089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505E36FFF08786BE11B7005DE4D3405E106 X-C1DE0DAB: 0D63561A33F958A526E4B240C2E203E350FAECFBC25836A4EC98A050F22CF6F5D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753530422897FB34C3410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34324A9840C798D500B00113A37FE531B6DF5CFE1379B82D6B6BBBBDA20172DFAF62AAB1402685C9221D7E09C32AA3244C0CB5BD50C8E228248E88E63D721C9A1DF165894D92D62706FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojPp/mPgZxawFHMBIjVbkA8g== X-Mailru-Sender: 3B9A0136629DC912F4AABCEFC589C81E75FFED161E14A853789A38F070AA5850DA7CE7CCD66FDF6BAD07DD1419AC565FA614486B47F28B67C5E079CCF3B0523AED31B7EB2E253A9E112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [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: Sergey Ostanevich via Tarantool-patches Reply-To: Sergey Ostanevich Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for the patch! I believe it=E2=80=99s unduly to ask for a test in this particular case. LGTM. Sergos > On 28 Jul 2021, at 00:24, Vladislav Shpilevoy = wrote: >=20 > 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. >=20 > 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. >=20 > 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(-) >=20 > 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 =3D NULL; > - char uuid_buf[UUID_STR_LEN + 1]; >=20 > if (lua_isstring(L, 1)) > buf =3D 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"); >=20 > - tt_uuid_to_string(&greeting.uuid, uuid_buf); > - lua_pushstring(L, uuid_buf); > + luaL_pushuuidstr(L, &greeting.uuid); > lua_setfield(L, -2, "uuid"); >=20 > 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" >=20 > int luaL_nil_ref =3D LUA_REFNIL; >=20 > @@ -107,6 +108,18 @@ luaL_pushuuid(struct lua_State *L) > return luaL_pushcdata(L, CTID_UUID); > } >=20 > +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); >=20 > +void > +luaL_pushuuidstr(struct lua_State *L, const struct tt_uuid *uuid); > + > /** \cond public */ >=20 > /** > --=20 > 2.24.3 (Apple Git-128) >=20