From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Roman Khabibov <roman.habibov@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: [tarantool-patches] Re: [PATCH] httpc: fix bug with segfault by wrong headers
Date: Mon, 22 Jul 2019 19:12:17 +0300 [thread overview]
Message-ID: <20190722161216.xzrs3wvjzqo3u37h@tkn_work_nb> (raw)
In-Reply-To: <01B8FFD0-AFA3-4821-AF68-2E17F08AF64A@tarantool.org>
> > It worth to fix this message, see
> > https://github.com/tarantool/tarantool/issues/4281#issuecomment-500477691
> > Please, mention the fix in the commit message, because it is the
> > behaviour change and it is not easy to observe in the patch itself due
> > to the code move.
As I see it is not done.
> >> + if (header_type != LUA_TTABLE)
> >> + return luaL_error(L, err_msg);
> >> + else if (!luaL_getmetafield(L, -1, "__tostring"))
> >> + return luaL_error(L, err_msg);
> >> + lua_pop(L, 1);
> >> + }
> >> + if (httpc_set_header(req, "%s: %s", lua_tostring(L, -2),
> >> + lua_tostring(L, -1)) < 0) {
> >
> > It was here before, but anyway:
> >
> > | While traversing a table, do not call lua_tolstring directly on a
> > | key, unless you know that the key is actually a string. Recall that
> > | lua_tolstring changes the value at the given index; this confuses the
> > | next call to lua_next.
> >
> > http://pgl.yoyo.org/luai/i/lua_next
> >
> > I would check that a key is a string too. This needs test cases and need
> > to be mentioned in the commit message.
Now I see, a number is not possible here, so the comment is not actual.
However I observer that __tostring is not called here and reopened
#3679.
> +/**
> + * Returns codes from fill_outgoing_headers().
> + */
> +enum headers_status {
> + HEADERS_SUCCESS = 0,
> + HEADERS_BAD_HEADERS = 1,
> + HEADERS_BAD_KEYS = 2,
> + HEADERS_INTERNAL_ERR = 3
> +};
Set a diag in a function and return -1 at an error. Using enum here
looks as overkill.
> -- gh-3679 allow only headers can be converted to string
> +-- gh-4281 allow only field 'headers' can be table and header keys
> +-- are defined
> local function test_request_headers(test, url, opts)
> - local exp_err = 'headers must be string or table with "__tostring"'
> + local exp_err = 'headers should be a string or a table with a "__tostring"'
> + local exp_err_non_table = '"headers" field should be a table'
> + local exp_err_bad_key = 'header key is non-defined'
Please, work on wording of comments and error messages. They are very
confusing in many ways:
* 'allow only headers can be converted to string' -- does you mean the
following?
> 'headers' option should be a table with fields that are strings or
> convertible to strings
* What is 'defined' and 'non-defined'? I don't know any common meaning
that would be applicable here.
> local cases = {
> {
> 'string header',
> @@ -324,6 +328,26 @@ local function test_request_headers(test, url, opts)
> opts = {headers = {aaa = setmetatable({}, {})}},
> exp_err = exp_err,
> },
> + {
> + 'string \'headers\'',
> + opts = {headers = 'aaa'},
> + exp_err = exp_err_non_table,
> + },
> + {
> + 'number \'headers\'',
> + opts = {headers = 1},
> + exp_err = exp_err_non_table,
> + },
> + {
> + 'cdata (box.NULL) \'headers\'',
> + opts = {headers = box.NULL},
> + exp_err = exp_err_non_table,
> + },
> + {
> + 'non-defined key',
> + opts = {headers = {'aaa'}},
> + exp_err = exp_err_bad_key,
> + },
> }
> test:plan(#cases)
>
> commit b3143a487d28b56c3965e160686a7f570d2d6e03
> Author: Roman Khabibov <roman.habibov@tarantool.org>
> Date: Sat Jun 15 19:46:28 2019 +0300
>
> httpc: fix bug with segfault by wrong headers
I would say it in more certain way, say, 'httpc: verify "headers" option
type'.
> There wasn't lua_istable() checking for field 'headers'. Raise an
> error if 'headers' field isn't a table. Also do it if a header key
> isn't determined.
How a key in a Lua table can be determined or not determined? I don't
know such term in this context.
next prev parent reply other threads:[~2019-07-22 16:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-16 15:24 [tarantool-patches] " Roman Khabibov
[not found] ` <20190624160423.ptng2eusy2osyyaj@tkn_work_nb>
2019-06-28 14:37 ` [tarantool-patches] " Roman Khabibov
2019-07-22 16:12 ` Alexander Turenko [this message]
2019-07-25 14:35 ` Roman Khabibov
2019-07-26 15:17 ` Alexander Turenko
2019-07-23 7:48 ` Alexander Turenko
2019-07-29 10:59 ` Kirill Yukhin
2019-07-29 12:25 ` Alexander Turenko
2019-07-29 14:24 ` Kirill Yukhin
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=20190722161216.xzrs3wvjzqo3u37h@tkn_work_nb \
--to=alexander.turenko@tarantool.org \
--cc=roman.habibov@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='[tarantool-patches] Re: [PATCH] httpc: fix bug with segfault by wrong headers' \
/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