From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Subject: [Tarantool-patches] [PATCH 04/16] iconv: take errno before reseting the context Date: Sat, 20 Mar 2021 01:42:41 +0100 [thread overview] Message-ID: <35c2067fefda1b36dda8c67209f6dd6327b64c61.1616200860.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1616200860.git.v.shpilevoy@tarantool.org> In Lua iconv_convert() in case ffi.C.tnt_iconv() with normal arguments failed, tried to clear iconv context by calling the function again with all arguments NULL. Then it looked at errno. But the second call could do anything with errno. For instance, it could also fail, and change errno. The patch saves errno into a variable before calling tnt_iconv() second time. It still does not give a perfect protection as it was discovered in scope of #5632, but still better. The patch is mostly motivated by the next patches about #5632 which will add another call to the error path, and it should better be after errno save. Needed for #5632 --- src/lua/iconv.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/lua/iconv.lua b/src/lua/iconv.lua index ade66d760..e68509dec 100644 --- a/src/lua/iconv.lua +++ b/src/lua/iconv.lua @@ -43,15 +43,18 @@ local function iconv_convert(iconv, data) buf_left[0] = buf:unused() local res = ffi.C.tnt_iconv(iconv, data_ptr, data_left, buf_ptr, buf_left) - if res == ffi.cast('size_t', -1) and errno() ~= E2BIG then - ffi.C.tnt_iconv(iconv, nil, nil, nil, nil) - if errno() == EINVAL then - error('Invalid multibyte sequence') + if res == ffi.cast('size_t', -1) then + local err = errno() + if err ~= E2BIG then + ffi.C.tnt_iconv(iconv, nil, nil, nil, nil) + if err == EINVAL then + error('Invalid multibyte sequence') + end + if err == EILSEQ then + error('Incomplete multibyte sequence') + end + error('Unknown conversion error: ' .. errno.strerror(err)) end - if errno() == EILSEQ then - error('Incomplete multibyte sequence') - end - error('Unknown conversion error: ' .. errno.strerror()) end buf:alloc(buf:unused() - buf_left[0]) end -- 2.24.3 (Apple Git-128)
next prev parent reply other threads:[~2021-03-20 0:48 UTC|newest] Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-20 0:42 [Tarantool-patches] [PATCH 00/16] Cord buffer, static alloc, and Lua GC bug Vladislav Shpilevoy via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 01/16] fio: don't use shared buffer in pread() Vladislav Shpilevoy via Tarantool-patches 2021-03-22 7:19 ` Cyrill Gorcunov via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 10/16] uri: replace static_alloc with ffi stash and ibuf Vladislav Shpilevoy via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 11/16] buffer: remove static_alloc() from Lua Vladislav Shpilevoy via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 12/16] lua: use lua_pushfstring() instead of tt_sprintf() Vladislav Shpilevoy via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 13/16] sio: rework sio_strfaddr() Vladislav Shpilevoy via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 14/16] sio: increase SERVICE_NAME_MAXLEN size Vladislav Shpilevoy via Tarantool-patches 2021-03-21 21:58 ` Cyrill Gorcunov via Tarantool-patches 2021-03-22 22:32 ` Vladislav Shpilevoy via Tarantool-patches 2021-03-23 6:56 ` Cyrill Gorcunov via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 15/16] sio: introduce and use sio_snprintf() Vladislav Shpilevoy via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 16/16] buffer: remove Lua registers Vladislav Shpilevoy via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 02/16] test: don't use IBUF_SHARED in the tests Vladislav Shpilevoy via Tarantool-patches 2021-03-22 7:35 ` Cyrill Gorcunov via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 03/16] tuple: pass global ibuf explicitly where possible Vladislav Shpilevoy via Tarantool-patches 2021-03-20 0:42 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 05/16] cord_buf: introduce cord_buf API Vladislav Shpilevoy via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 06/16] cord_buf: introduce ownership management Vladislav Shpilevoy via Tarantool-patches 2021-03-22 16:48 ` Serge Petrenko via Tarantool-patches 2021-03-22 22:32 ` Vladislav Shpilevoy via Tarantool-patches 2021-03-23 7:46 ` Serge Petrenko via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 07/16] buffer: implement ffi stash Vladislav Shpilevoy via Tarantool-patches 2021-03-23 0:29 ` Vladislav Shpilevoy via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 08/16] uuid: replace static_alloc with " Vladislav Shpilevoy via Tarantool-patches 2021-03-20 0:42 ` [Tarantool-patches] [PATCH 09/16] uuid: drop tt_uuid_str() from Lua Vladislav Shpilevoy via Tarantool-patches 2021-03-21 16:38 ` [Tarantool-patches] [PATCH 00/16] Cord buffer, static alloc, and Lua GC bug Vladislav Shpilevoy via Tarantool-patches 2021-03-22 7:52 ` Cyrill Gorcunov via Tarantool-patches 2021-03-22 7:56 ` Konstantin Osipov via Tarantool-patches 2021-03-22 17:17 ` Serge Petrenko via Tarantool-patches 2021-03-23 23:45 ` Vladislav Shpilevoy via Tarantool-patches 2021-03-24 13:28 ` 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=35c2067fefda1b36dda8c67209f6dd6327b64c61.1616200860.git.v.shpilevoy@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=gorcunov@gmail.com \ --cc=sergepetrenko@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 04/16] iconv: take errno before reseting the context' \ /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