Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Ostanevich via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH 1/5] uuid: introduce and use luaL_pushuuidstr()
Date: Thu, 29 Jul 2021 14:30:38 +0300	[thread overview]
Message-ID: <E5925B83-AA74-4C17-84EC-A43CE7092049@tarantool.org> (raw)
In-Reply-To: <0104ef1d3f256b7e062806b5a29fe42525ec1b77.1627420835.git.v.shpilevoy@tarantool.org>

Hi!

Thanks for the patch!
I believe it’s unduly to ask for a test in this particular case.

LGTM.

Sergos

> On 28 Jul 2021, at 00:24, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote:
> 
> 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.
> 
> 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.
> 
> 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(-)
> 
> 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 = NULL;
> -	char uuid_buf[UUID_STR_LEN + 1];
> 
> 	if (lua_isstring(L, 1))
> 		buf = 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");
> 
> -	tt_uuid_to_string(&greeting.uuid, uuid_buf);
> -	lua_pushstring(L, uuid_buf);
> +	luaL_pushuuidstr(L, &greeting.uuid);
> 	lua_setfield(L, -2, "uuid");
> 
> 	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 <trivia/util.h>
> #include <diag.h>
> #include <fiber.h>
> +#include "uuid/tt_uuid.h"
> 
> int luaL_nil_ref = LUA_REFNIL;
> 
> @@ -107,6 +108,18 @@ luaL_pushuuid(struct lua_State *L)
> 	return luaL_pushcdata(L, CTID_UUID);
> }
> 
> +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);
> 
> +void
> +luaL_pushuuidstr(struct lua_State *L, const struct tt_uuid *uuid);
> +
> /** \cond public */
> 
> /**
> -- 
> 2.24.3 (Apple Git-128)
> 


  reply	other threads:[~2021-07-29 11:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27 21:24 [Tarantool-patches] [PATCH 0/5] Static buf in Lua, part 3 Vladislav Shpilevoy via Tarantool-patches
2021-07-27 21:24 ` [Tarantool-patches] [PATCH 1/5] uuid: introduce and use luaL_pushuuidstr() Vladislav Shpilevoy via Tarantool-patches
2021-07-29 11:30   ` Sergey Ostanevich via Tarantool-patches [this message]
2021-07-27 21:24 ` [Tarantool-patches] [PATCH 2/5] info: use luaL_pushuuidstr() for box.info uuids Vladislav Shpilevoy via Tarantool-patches
2021-07-29 11:38   ` Sergey Ostanevich via Tarantool-patches
2021-08-01 15:03     ` Vladislav Shpilevoy via Tarantool-patches
2021-08-01 17:01       ` Sergey Ostanevich via Tarantool-patches
2021-07-27 21:24 ` [Tarantool-patches] [PATCH 3/5] decimal: rename decimal_to_string to decimal_str Vladislav Shpilevoy via Tarantool-patches
2021-07-29 11:41   ` Sergey Ostanevich via Tarantool-patches
2021-08-01 15:03     ` Vladislav Shpilevoy via Tarantool-patches
2021-08-01 17:01       ` Sergey Ostanevich via Tarantool-patches
2021-07-27 21:24 ` [Tarantool-patches] [PATCH 4/5] decimal: introduce decimal_to_string Vladislav Shpilevoy via Tarantool-patches
2021-07-29 11:52   ` Sergey Ostanevich via Tarantool-patches
2021-08-01 15:04     ` Vladislav Shpilevoy via Tarantool-patches
2021-08-01 17:06       ` Sergey Ostanevich via Tarantool-patches
2021-07-27 21:24 ` [Tarantool-patches] [PATCH 5/5] decimal: introduce and use lua_pushdecimalstr() Vladislav Shpilevoy via Tarantool-patches
2021-07-29 12:28   ` Sergey Ostanevich via Tarantool-patches
2021-08-01 15:04     ` Vladislav Shpilevoy via Tarantool-patches
2021-07-27 21:39 ` [Tarantool-patches] [PATCH 0/5] Static buf in Lua, part 3 Cyrill Gorcunov via Tarantool-patches
2021-08-02 19:45 ` Vladislav Shpilevoy via Tarantool-patches

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=E5925B83-AA74-4C17-84EC-A43CE7092049@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=sergos@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 1/5] uuid: introduce and use luaL_pushuuidstr()' \
    /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