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 7D5146EC55; Thu, 29 Jul 2021 14:38:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7D5146EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627558685; bh=A0uxuVK4vfaIEOosMVEdGzj6JluPeECuI44jkG+GR3w=; 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=EaQPQiKacNkNDvEj0rVr8ykgzvfQuFBBpJZFYZjbaTIkOroygE0N1Mdq77uC/NOw3 OvEvg2+lwh+iefnzjMLYC+359nWa5C1XELataI/xPlh+p0bw2CH37cXyfJiAacPZMz aRZ8pL1lPFsJ1MxXwLZgIGyASNc921B4B9V+67I4= Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [94.100.177.112]) (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 3E3126EC55 for ; Thu, 29 Jul 2021 14:38:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3E3126EC55 Received: by smtp52.i.mail.ru with esmtpa (envelope-from ) id 1m94MV-0006hj-7Y; Thu, 29 Jul 2021 14:38:03 +0300 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.100.0.2.22\)) In-Reply-To: Date: Thu, 29 Jul 2021 14:38:01 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Vladislav Shpilevoy X-Mailer: Apple Mail (2.3654.100.0.2.22) X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C366EE405EC28A2001F8302D8429E0DE58182A05F53808504062465DAD50905A60EF36D05375E031A351E69A0985B7A67736E1FE858405D516 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE76DA1643ED1288E2AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AAF0FBE7E77B7ED78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8D1654B2FF09C40E0BE1486D44926B508117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD186FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B67393CE827C55B5F775ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A5C89B0273A26861551067284EF731B1F465C2E607CA77D0AAD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753530422897FB34C3410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3441661D6226BE8C31B2FE68DCF91ACB2D987216396124D2AD054D36215C63F1B3BA99FAE5D686BF731D7E09C32AA3244CE1EBE9C79FF38D8CBEDBAFA2E2B8D7BD9CA7333006C390A0FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojPp/mPgZxawG9lwwWAqfcLg== X-Mailru-Sender: 3B9A0136629DC912F4AABCEFC589C81E06F8044323D3EAA6E92DC3B35081D8447E500A85F8B933EDAD07DD1419AC565FA614486B47F28B67C5E079CCF3B0523AED31B7EB2E253A9E112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 2/5] info: use luaL_pushuuidstr() for box.info uuids 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, just one comment below. Sergos > On 28 Jul 2021, at 00:24, Vladislav Shpilevoy = wrote: >=20 > box.info.uuid, box.info.cluster.uuid, and box.info.* replica UUIDs > used tt_uuid_str() function. The function is not safe to use in > preemptive context like Lua, where any attempt to push something > onto the Lua stack might trigger GC, which in turn might invoke > any other code. >=20 > It is not safe because uses the static buffer, which is global and > cyclic. Newer allocations can override the old data without any > warning. >=20 > Follow up #5632 > Follow up #6050 > Part of #6259 > --- > src/box/lua/info.c | 8 ++-- > ...> gh-5632-6050-6259-gc-buf-reuse.test.lua} | 48 ++++++++++++++++--- > 2 files changed, 46 insertions(+), 10 deletions(-) > rename test/app-tap/{gh-5632-6050-gc-buf-reuse.test.lua =3D> = gh-5632-6050-6259-gc-buf-reuse.test.lua} (79%) >=20 > diff --git a/src/box/lua/info.c b/src/box/lua/info.c > index 1d8fe7938..d297ec6f6 100644 > --- a/src/box/lua/info.c > +++ b/src/box/lua/info.c > @@ -176,7 +176,7 @@ lbox_pushreplica(lua_State *L, struct replica = *replica) > lua_settable(L, -3); >=20 > lua_pushstring(L, "uuid"); > - lua_pushstring(L, tt_uuid_str(&replica->uuid)); > + luaL_pushuuidstr(L, &replica->uuid); > lua_settable(L, -3); >=20 > lua_pushstring(L, "lsn"); > @@ -235,7 +235,7 @@ lbox_info_replication_anon_call(struct lua_State = *L) > if (!replica->anon) > continue; >=20 > - lua_pushstring(L, tt_uuid_str(&replica->uuid)); > + luaL_pushuuidstr(L, &replica->uuid); > lbox_pushreplica(L, replica); >=20 > lua_settable(L, -3); > @@ -290,7 +290,7 @@ lbox_info_id(struct lua_State *L) > static int > lbox_info_uuid(struct lua_State *L) > { > - lua_pushlstring(L, tt_uuid_str(&INSTANCE_UUID), UUID_STR_LEN); > + luaL_pushuuidstr(L, &INSTANCE_UUID); > return 1; > } >=20 > @@ -376,7 +376,7 @@ lbox_info_cluster(struct lua_State *L) > { > lua_createtable(L, 0, 2); > lua_pushliteral(L, "uuid"); > - lua_pushlstring(L, tt_uuid_str(&REPLICASET_UUID), UUID_STR_LEN); > + luaL_pushuuidstr(L, &REPLICASET_UUID); > lua_settable(L, -3); > return 1; > } > diff --git a/test/app-tap/gh-5632-6050-gc-buf-reuse.test.lua = b/test/app-tap/gh-5632-6050-6259-gc-buf-reuse.test.lua > similarity index 79% > rename from test/app-tap/gh-5632-6050-gc-buf-reuse.test.lua > rename to test/app-tap/gh-5632-6050-6259-gc-buf-reuse.test.lua > index bf7590a14..f806ba6b7 100755 > --- a/=09 > +++ b/test/app-tap/gh-5632-6050-6259-gc-buf-reuse.test.lua > @@ -1,10 +1,10 @@ > #!/usr/bin/env tarantool >=20 > -- > --- gh-5632, gh-6050: Lua code should not use any global buffers or = objects > --- without proper ownership protection. Otherwise these items might = be suddenly > --- reused during Lua GC which happens almost at any moment. That = might lead to > --- data corruption. > +-- gh-5632, gh-6050, gh-6259: Lua code should not use any global = buffers or > +-- objects without proper ownership protection. Otherwise these items = might be > +-- suddenly reused during Lua GC which happens almost at any moment. = That might > +-- lead to data corruption. > -- >=20 > local tap =3D require('tap') > @@ -190,11 +190,47 @@ local function test_json(test) > test:ok(is_success, 'json in gc') > end >=20 > -local test =3D tap.test('gh-5632-6050-gc-buf-reuse') > -test:plan(4) > +local function test_info_uuid(test) > + test:plan(1) > + > + local gc_count =3D 100 > + local iter_count =3D 1000 > + local is_success =3D true > + > + local function uuid_to_str() > + local uu =3D uuid.new() > + local str1 =3D box.info.uuid > + local str2 =3D box.info.cluster.uuid > + local str3 =3D box.info.uuid > + local str4 =3D box.info.cluster.uuid > + if str1 ~=3D str3 or str2 ~=3D str4 then > + is_success =3D false > + assert(false) Why did you keep the assert? I believe there should be just a non-ok in = test? > + end > + end > + > + local function create_gc() > + for _ =3D 1, gc_count do > + ffi.gc(ffi.new('char[1]'), function() uuid_to_str() end) > + end > + end > + > + for _ =3D 1, iter_count do > + create_gc() > + uuid_to_str() > + end > + > + test:ok(is_success, 'info uuid in gc') > +end > + > +box.cfg{} > + > +local test =3D tap.test('gh-5632-6050-6259-gc-buf-reuse') > +test:plan(5) > test:test('uuid in __gc', test_uuid) > test:test('uri in __gc', test_uri) > test:test('msgpackffi in __gc', test_msgpackffi) > test:test('json in __gc', test_json) > +test:test('info uuid in __gc', test_info_uuid) >=20 > os.exit(test:check() and 0 or 1) > --=20 > 2.24.3 (Apple Git-128) >=20