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 BD5636FC8F; Thu, 25 Mar 2021 00:29:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BD5636FC8F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616621381; bh=3P0YOAIcGsR7ok3TbrONciTc+rEEWu7zJ/cFIAlGPmM=; 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=uIoBUT53rZ4uaytxQeb3Ybe7Y5E2hBh7YOnkDiYl7SbXnnBbA1YvVVPX+4AcnHrjc cwrc2jgBsyT+yJarRE5KrIbXn7vuAgU5mm3Squnl2od5Q4czCJJKZ4YdPwSkRFeiuy CgQw1ZywRv2QtGe3LJ0pAATJHjH0bYKQVTOkD/jY= Received: from smtp48.i.mail.ru (smtp48.i.mail.ru [94.100.177.108]) (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 6F10A6AA80 for ; Thu, 25 Mar 2021 00:24:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6F10A6AA80 Received: by smtp48.i.mail.ru with esmtpa (envelope-from ) id 1lPAzg-0004ib-88; Thu, 25 Mar 2021 00:24:48 +0300 To: tarantool-patches@dev.tarantool.org, kyukhin@tarantool.org Date: Wed, 24 Mar 2021 22:24:30 +0100 Message-Id: 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: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9064ADF4728AA0EE92C031F1727A757A9F762E9876BADF49A182A05F53808504091C53CC29968CFABF7B8930A025FB50BD53B33EA419B08E574EACE277CE089AF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70312E9A300D47E3BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637B9ECF1867A781AFF8638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C5DD32608FC869F5DB92DDC7154C2C210A7C7C8FE6BA0C423A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE709B92020B71E24959FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3FD59DAE6580CC3C3117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CFCA64746D51DB396CBA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6EA6D1ABBF2123E0276E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B3BBE47FD9DD3FB59A8DF7F3B2552694A2BEBFE083D3B9BA73A03B725D353964BB11811A4A51E3B096D1867E19FE14079BA9C0B312567BB23089D37D7C0E48F6CA18204E546F3947CB26E97DCB74E625257739F23D657EF2BC8A9BA7A39EFB7666BA297DBC24807EA089D37D7C0E48F6C8AA50765F790063757B1FBEA53BC6EDBEFF80C71ABB335746BA297DBC24807EA27F269C8F02392CD6143B1329D1CCA5627F269C8F02392CD5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824AC8B6CDF511875BC4E8F7B195E1C97831148145A0506FFD4863EC326E2DBBB914 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C5DD32608FC869F5DB92DDC7154C2C210A7C7C8FE6BA0C4239C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D344E332383F80D58BB9B2162B93AFEA3CD771471809AA2DC70BA4EF9749587C32B3C1E4D4EE5F43EF11D7E09C32AA3244C344BEA2DE8492EFEC591414CEEDE7AA53C6EB905E3A8056B729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojjqzNotmU+gdwe/aQgcu+8w== X-Mailru-Sender: 504CC1E875BF3E7D9BC0E5172ADA3110A906815429F9D960FBADEA0B92A408E74D721902B9AA238607784C02288277CA03E0582D3806FB6A5317862B1921BA260ED6CFD6382C13A6112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH 04/15] 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 (cherry picked from commit 8c48974448f846629873302f0200c0a1505d40b7) --- 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)