From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tarantool-patches@dev.tarantool.org, kyukhin@tarantool.org
Subject: [Tarantool-patches] [PATCH 11/15] lua: use lua_pushfstring() instead of tt_sprintf()
Date: Wed, 24 Mar 2021 22:24:23 +0100 [thread overview]
Message-ID: <1fffad7430a9a709921c8a0900a77f2cd10e2d45.1616620860.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1616620860.git.v.shpilevoy@tarantool.org>
In a few places to push a formatted string was used 2 calls:
tt_sprintf() + lua_pushstring(). It wasn't necessary because Lua
API has lua_pushfstring() with a big enough subset of printf
format features.
But more importantly - it was a bug. lua_pushstring() is a GC
point. Before copying the passed string it tries to invoke Lua GC,
which might invoke a __gc handler for some cdata, where static
alloc might be used, and it can rewrite the string passed to
lua_pushstring() in the beginning of the stack.
Part of #5632
(cherry picked from commit b3872a38b1e4be6a84d0621c833a196baf70284f)
---
src/box/lua/space.cc | 6 ++----
src/lua/utf8.c | 5 ++---
2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc
index 9ea0d6f7e..962796e6a 100644
--- a/src/box/lua/space.cc
+++ b/src/box/lua/space.cc
@@ -480,8 +480,7 @@ lbox_space_frommap(struct lua_State *L)
space = space_by_id(id);
if (space == NULL) {
lua_pushnil(L);
- lua_pushstring(L, tt_sprintf("Space with id '%d' "\
- "doesn't exist", id));
+ lua_pushfstring(L, "Space with id '%d' doesn't exist", id);
return 2;
}
assert(space->format != NULL);
@@ -498,8 +497,7 @@ lbox_space_frommap(struct lua_State *L)
if (tuple_fieldno_by_name(dict, key, key_len, key_hash,
&fieldno)) {
lua_pushnil(L);
- lua_pushstring(L, tt_sprintf("Unknown field '%s'",
- key));
+ lua_pushfstring(L, "Unknown field '%s'", key);
return 2;
}
lua_rawseti(L, -3, fieldno+1);
diff --git a/src/lua/utf8.c b/src/lua/utf8.c
index 0d9c49a8b..53cdcb023 100644
--- a/src/lua/utf8.c
+++ b/src/lua/utf8.c
@@ -83,9 +83,8 @@ utf8_str_to_case(struct lua_State *L, const char *src, int src_bsize,
} else {
cord_ibuf_put(ibuf);
lua_pushnil(L);
- lua_pushstring(L, tt_sprintf("error during ICU case "\
- "transform: %s",
- u_errorName(err)));
+ lua_pushfstring(L, "error during ICU case "
+ "transform: %s", u_errorName(err));
return 2;
}
/*
--
2.24.3 (Apple Git-128)
next prev parent reply other threads:[~2021-03-24 21:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-24 21:24 [Tarantool-patches] [PATCH 00/15] Cord buffer, static alloc, and Lua GC bug for 1.10 Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 01/15] fio: don't use shared buffer in pread() Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 10/15] uri: replace static_alloc with ffi stash and ibuf Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` Vladislav Shpilevoy via Tarantool-patches [this message]
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 12/15] sio: rework sio_strfaddr() Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 13/15] sio: increase SERVICE_NAME_MAXLEN size Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 14/15] sio: introduce and use sio_snprintf() Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 15/15] buffer: remove Lua registers Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 02/15] test: don't use IBUF_SHARED in the tests Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 03/15] tuple: pass global ibuf explicitly where possible Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 04/15] iconv: take errno before reseting the context Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 05/15] cord_buf: introduce cord_buf API Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 06/15] cord_buf: introduce ownership management Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 07/15] buffer: implement ffi stash Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 08/15] uuid: replace static_alloc with " Vladislav Shpilevoy via Tarantool-patches
2021-03-24 21:24 ` [Tarantool-patches] [PATCH 09/15] uuid: drop tt_uuid_str() from Lua Vladislav Shpilevoy via Tarantool-patches
2021-03-29 15:41 ` [Tarantool-patches] [PATCH 00/15] Cord buffer, static alloc, and Lua GC bug for 1.10 Kirill Yukhin 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=1fffad7430a9a709921c8a0900a77f2cd10e2d45.1616620860.git.v.shpilevoy@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=kyukhin@tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH 11/15] lua: use lua_pushfstring() instead of tt_sprintf()' \
/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