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 798776EC55; Wed, 28 Jul 2021 00:25:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 798776EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627421118; bh=yGxjD/qx+cnRz96gNh5p8hKePgljUzeHRBAGLNDaGT8=; 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=ho77MmOM7ltaIXy63cIiyDisubfQTdBESMAq9j2zrscHQb7u/IgXqW5FJJVSIXxSi rOaOx+S6D/hFSt11bk+oSOP67w+KKR7a3oKiDkkxWl0O3SILj8lWwCi8qp02AedLM6 R/NfRWkX0V8iOZk6vBF2fZlTYHaxVsl8QzFo90KQ= 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 1BFDF6EC56 for ; Wed, 28 Jul 2021 00:24:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1BFDF6EC56 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1m8UYk-0005in-BB; Wed, 28 Jul 2021 00:24:18 +0300 To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergos@tarantool.org Date: Tue, 27 Jul 2021 23:24:12 +0200 Message-Id: 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: 4F1203BC0FB41BD941C43E597735A9C3038391AAE5FBFA7682283CBB09BF492D182A05F538085040A0ED5198D29BF7BC5D198BC3D91161B14556DCE24F762E1EA15803D03C539F9F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE71AA0644833F53075EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637FDB3827A455F08028638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8D766EEB9D8068911CE66DF1A4BF73466117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAE9A1BBD95851C5BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18BDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B613439FA09F3DCB32089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7BEA09003D200E08032EA63E0870F8F0877820732E53DE5B9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFA5DF9383870C0FED699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A5970F8A4685C8ABED5FD4595ABB16EAD7D36B1F50FB225DE1F8D365A0F3E28A538AF1F6EA84D7301D7E09C32AA3244C59DD2E7301E4CF1977C698D2BDA09CC5795D98D676DD64D0FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojiF1u9eOpfTSgkWNFz0s87g== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D6A485CE6404D38A1847DF7A3F89608883841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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. It is not safe because uses the static buffer, which is global and cyclic. Newer allocations can override the old data without any warning. 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 => gh-5632-6050-6259-gc-buf-reuse.test.lua} (79%) 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); lua_pushstring(L, "uuid"); - lua_pushstring(L, tt_uuid_str(&replica->uuid)); + luaL_pushuuidstr(L, &replica->uuid); lua_settable(L, -3); lua_pushstring(L, "lsn"); @@ -235,7 +235,7 @@ lbox_info_replication_anon_call(struct lua_State *L) if (!replica->anon) continue; - lua_pushstring(L, tt_uuid_str(&replica->uuid)); + luaL_pushuuidstr(L, &replica->uuid); lbox_pushreplica(L, replica); 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; } @@ -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/test/app-tap/gh-5632-6050-gc-buf-reuse.test.lua +++ b/test/app-tap/gh-5632-6050-6259-gc-buf-reuse.test.lua @@ -1,10 +1,10 @@ #!/usr/bin/env tarantool -- --- 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. -- local tap = require('tap') @@ -190,11 +190,47 @@ local function test_json(test) test:ok(is_success, 'json in gc') end -local test = tap.test('gh-5632-6050-gc-buf-reuse') -test:plan(4) +local function test_info_uuid(test) + test:plan(1) + + local gc_count = 100 + local iter_count = 1000 + local is_success = true + + local function uuid_to_str() + local uu = uuid.new() + local str1 = box.info.uuid + local str2 = box.info.cluster.uuid + local str3 = box.info.uuid + local str4 = box.info.cluster.uuid + if str1 ~= str3 or str2 ~= str4 then + is_success = false + assert(false) + end + end + + local function create_gc() + for _ = 1, gc_count do + ffi.gc(ffi.new('char[1]'), function() uuid_to_str() end) + end + end + + for _ = 1, iter_count do + create_gc() + uuid_to_str() + end + + test:ok(is_success, 'info uuid in gc') +end + +box.cfg{} + +local test = 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) os.exit(test:check() and 0 or 1) -- 2.24.3 (Apple Git-128)