Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org, imeevma@tarantool.org
Subject: [tarantool-patches] Re: [PATCH v8 1/6] lua: remove exceptions from function luaL_tofield()
Date: Tue, 29 Jan 2019 23:42:28 +0300	[thread overview]
Message-ID: <e128093a-f4f0-202b-55b2-9cc0e750fae4@tarantool.org> (raw)
In-Reply-To: <f3d5e7ec4d7b75f81a022ce196fc2a8fdd4f5b98.1547902954.git.imeevma@gmail.com>

Hi! Thanks for the patch! See 2 comments below.

> @@ -525,94 +533,95 @@ luaL_tofield(struct lua_State *L, struct luaL_serializer *cfg, int index,
>   	case LUA_TBOOLEAN:
>   		field->type = MP_BOOL;
>   		field->bval = lua_toboolean(L, index);
> -		return;
> +		return 0;
>   	case LUA_TNIL:
>   		field->type = MP_NIL;
> -		return;
> +		return 0;
>   	case LUA_TSTRING:
>   		field->sval.data = lua_tolstring(L, index, &size);
>   		field->sval.len = (uint32_t) size;
>   		field->type = MP_STR;
> -		return;
> +		return 0;
>   	case LUA_TTABLE:
>   	{
>   		field->compact = false;
> -		lua_field_inspect_table(L, cfg, index, field);
> -		return;
> +		if (lua_field_inspect_table(L, cfg, index, field) < 0)
> +			return -1;
> +		return 0;

1. Why not simply 'return lua_field_inspect_table' ?

>   	}
>   	case LUA_TLIGHTUSERDATA:
>   	case LUA_TUSERDATA:
> diff --git a/src/lua/utils.h b/src/lua/utils.h
> index a47e3d2..fde3514 100644
> --- a/src/lua/utils.h
> +++ b/src/lua/utils.h
> @@ -345,7 +348,8 @@ static inline void
>   luaL_checkfield(struct lua_State *L, struct luaL_serializer *cfg, int idx,
>   		struct luaL_field *field)
>   {
> -	luaL_tofield(L, cfg, idx, field);
> +	if (luaL_tofield(L, cfg, idx, field) < 0)
> +		luaT_error(L);
>   	if (field->type != MP_EXT)
>   		return;
>   	luaL_convertfield(L, cfg, idx, field);
> -- 
> 2.7.4
> 
> 

2. Looking at lua_field_inspect_table I found that if a table has __serialize
metamethod, it is called without a protection (utils.c:409). __serialize is an
arbitrary unprotected user code, that can throw an error deliberately. What are
we gonna do with that? Personally I've already faced with some user code, throwing
an error from __serialize, deliberately. On not critical errors not meaning panic.

As a solution we could 1) do not care, again; 2) finally accept the fact that
wrap into a pcall was not so bad and use it; 3) use lua_pcall in that
particular place. Please, consult Kostja, what does he choose.

  parent reply	other threads:[~2019-01-29 20:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-19 13:20 [tarantool-patches] [PATCH v8 0/6] sql: remove box.sql.execute imeevma
2019-01-19 13:20 ` [tarantool-patches] [PATCH v8 1/6] lua: remove exceptions from function luaL_tofield() imeevma
2019-01-22 19:58   ` [tarantool-patches] " Vladislav Shpilevoy
2019-01-24  7:27     ` Imeev Mergen
2019-01-29 20:42   ` Vladislav Shpilevoy [this message]
2019-01-19 13:20 ` [tarantool-patches] [PATCH v8 2/6] iproto: move map creation to sql_response_dump() imeevma
2019-01-25 16:07   ` [tarantool-patches] " Konstantin Osipov
2019-01-29 20:42     ` Vladislav Shpilevoy
2019-01-19 13:20 ` [tarantool-patches] [PATCH v8 3/6] iproto: create port_sql imeevma
2019-01-19 13:20 ` [tarantool-patches] [PATCH v8 4/6] lua: create method dump_lua for port_sql imeevma
2019-01-29 20:42   ` [tarantool-patches] " Vladislav Shpilevoy
2019-01-19 13:20 ` [tarantool-patches] [PATCH v8 5/6] lua: parameter binding for new execute() imeevma
2019-01-19 13:20 ` [tarantool-patches] [PATCH v8 6/6] sql: check new box.sql.execute() imeevma
2019-01-22 19:58 ` [tarantool-patches] Re: [PATCH v8 0/6] sql: remove box.sql.execute Vladislav Shpilevoy
2019-01-24  7:31   ` Imeev Mergen

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=e128093a-f4f0-202b-55b2-9cc0e750fae4@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v8 1/6] lua: remove exceptions from function luaL_tofield()' \
    /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