From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id A16762EA4E for ; Sun, 2 Jun 2019 16:24:16 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hXwuoYVCnBLa for ; Sun, 2 Jun 2019 16:24:16 -0400 (EDT) Received: from smtp36.i.mail.ru (smtp36.i.mail.ru [94.100.177.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 14F0E2E346 for ; Sun, 2 Jun 2019 16:24:15 -0400 (EDT) Received: by smtp36.i.mail.ru with esmtpa (envelope-from ) id 1hXX1Y-0002KS-De for tarantool-patches@freelists.org; Sun, 02 Jun 2019 23:24:14 +0300 From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH 1/1] swim: do not return raw member tt_uuid pointer Date: Sun, 2 Jun 2019 22:24:06 +0200 Message-Id: <2945a5540305ff711c80ff6b80e42f3d95b840a8.1559506757.git.v.shpilevoy@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org When a member is deleted, pointer at its struct tt_uuid becomes invalid. This commit makes member:uuid() create a new tt_uuid object, cached for subsequent calls. --- Branch: https://github.com/tarantool/tarantool/tree/gerold103/swim-member-use-after-free src/lua/swim.lua | 10 +++++++++- test/swim/swim.result | 4 ++++ test/swim/swim.test.lua | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lua/swim.lua b/src/lua/swim.lua index 4893d5767..adb102d06 100644 --- a/src/lua/swim.lua +++ b/src/lua/swim.lua @@ -391,7 +391,15 @@ end -- metatable, serialization, string conversions etc. -- local function swim_member_uuid(m) - return capi.swim_member_uuid(swim_check_member(m, 'member:uuid()')) + local ptr = swim_check_member(m, 'member:uuid()') + local u = m.u + if not u then + ptr = capi.swim_member_uuid(ptr) + u = ffi.new('struct tt_uuid') + ffi.copy(u, ptr, ffi.sizeof('struct tt_uuid')) + rawset(m, 'u', u) + end + return u end local function swim_member_serialize(m) diff --git a/test/swim/swim.result b/test/swim/swim.result index 436d4e579..5696d984b 100644 --- a/test/swim/swim.result +++ b/test/swim/swim.result @@ -403,6 +403,10 @@ s:uuid() --- - 00000000-0000-1000-8000-000000000001 ... +s:uuid() == s:uuid() +--- +- true +... s:uri() --- - 127.0.0.1: diff --git a/test/swim/swim.test.lua b/test/swim/swim.test.lua index a3eac9b46..44376e3db 100644 --- a/test/swim/swim.test.lua +++ b/test/swim/swim.test.lua @@ -137,6 +137,7 @@ s = s1:self() s s:status() s:uuid() +s:uuid() == s:uuid() s:uri() s:incarnation() s:payload_cdata() -- 2.20.1 (Apple Git-117)