From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 7C5386EC56; Sat, 20 Mar 2021 03:48:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7C5386EC56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616201306; bh=FjXl1+mpEAIe08FMRUGr/0EhZbCOnhEdMGzEW3dmF3k=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=E5a0XRw9R3NiT/+dJ9MT7QuUJj//4+sRIi2HurN3WP7O4M2zJUopmvCeqwFxI8E7A cx0L7ozQ4FlJgjLtEjLXZSRTDpcRCpzEgHZjt2xExXhtFL9eV0xgOGB1e0cHbX6kPs fickbM5labgV81fyo69YOx43i2lgycRbC3+EYeYQ= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 602A57030D for ; Sat, 20 Mar 2021 03:43:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 602A57030D Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lNPhn-00076U-Il; Sat, 20 Mar 2021 03:43:04 +0300 To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Date: Sat, 20 Mar 2021 01:42:41 +0100 Message-Id: <35c2067fefda1b36dda8c67209f6dd6327b64c61.1616200860.git.v.shpilevoy@tarantool.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F10D3016C09B407F8B1E2E766A3410B623182A05F538085040D588BC60FACE9A83619D78F8061590488EC9CF33F4A838C5E1755A31B515998B X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70CB15FA6C489297DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063775FF68B4B43662428638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C81A23F326053F8273B15A1427352256E1222D4C802507A27A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE7850F8B975A76562C9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3BEC81E4AEBD6D2BF117882F4460429728AD0CFFFB425014E868A13BD56FB6657A7F4EDE966BC389F9E8FC8737B5C2249753C3A5E0A5AB5B7089D37D7C0E48F6CCF19DD082D7633A0E7DDDDC251EA7DABAAAE862A0553A39223F8577A6DFFEA7C831C17AB68599A1243847C11F186F3C5E7DDDDC251EA7DABCC89B49CDF41148F90DBEB212AEC08F22623479134186CDE6BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2BBE337FB72E923155C0AF1600DCBC20BD3311767B7455A33536B03EE80A435A0 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C81A23F326053F8273B15A1427352256E1222D4C802507A279C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFF532FBFD8162E58C699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3475FE4AA98865E235C1F42E434A7207742C6CA50B8E9E8072E56CEBCE829319F85705560022254A461D7E09C32AA3244CF702957C4E0CFE2E071153578C00E271250262A5EE9971B0FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj8xHC0Ak4ylZlZVYE20x4/A== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822F52DC5F84AF06C2A869CAED363D32A9C3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 04/16] iconv: take errno before reseting the context X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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)