Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH 1/1] swim: do not return raw member tt_uuid pointer
Date: Sun,  2 Jun 2019 22:24:06 +0200	[thread overview]
Message-ID: <2945a5540305ff711c80ff6b80e42f3d95b840a8.1559506757.git.v.shpilevoy@tarantool.org> (raw)

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:<port>
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)

             reply	other threads:[~2019-06-02 20:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-02 20:24 Vladislav Shpilevoy [this message]
2019-06-08 14:09 ` [tarantool-patches] " Konstantin Osipov
2019-06-08 19:54   ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2945a5540305ff711c80ff6b80e42f3d95b840a8.1559506757.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 1/1] swim: do not return raw member tt_uuid pointer' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox