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 94EEA6F3F2; Fri, 3 Sep 2021 22:20:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 94EEA6F3F2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1630696829; bh=LNWlFC3PNODu5c/lqXVgyYA3OTL7flZj/rapmz7tH0E=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=SRNONzRLs4Vr7n59MDCjPwIJqG/EeY9ySCce4q3WAKhbLHdYN6MxAKHYK+37yOvI5 yGb8qkC1BcuNTjbEZuXmQkxjTkKcDKYXs0iuhiH4OY/KkKsoUzJPO3f396qB4XPSgU gmZWRZsNWFpyL8CvUSvN4U6l7vFhs6h35SzLwpL0= Received: from smtp55.i.mail.ru (smtp55.i.mail.ru [217.69.128.35]) (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 A540C6F3FC for ; Fri, 3 Sep 2021 22:20:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A540C6F3FC Received: by smtp55.i.mail.ru with esmtpa (envelope-from ) id 1mMEjK-0003aY-1F; Fri, 03 Sep 2021 22:20:02 +0300 To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <3fddf927be4ef819b63e172f29af58ac352da640.1630304393.git.imeevma@gmail.com> Message-ID: <5b9c9dbb-1de6-ac7c-b432-4e878873e83d@tarantool.org> Date: Fri, 3 Sep 2021 22:20:01 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <3fddf927be4ef819b63e172f29af58ac352da640.1630304393.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D96C1EA41D18F4D5E267050317C242BB27DD410512DDC118182A05F538085040FD8179045698ED16F503C9EFA2F3172E6352CBA12AAC34351043EB5815E4CEB1 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE72424932217190DC2EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063752AC809489EC5B9C8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8CFDA2297FEC40F3ED6D19E81C53050A9117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735209ECD01F8117BC8BEA471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FCB403722D27F53E293AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F790063728955CBBA6F7FF31D81D268191BDAD3D698AB9A7B718F8C4D1B931868CE1C5781A620F70A64A45A98AA50765F79006372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F616AD31D0D18CD5C57739F23D657EF2BB5C8C57E37DE458BEDA766A37F9254B7 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79DB8BF922E402C092CA7093BF4FD113181 X-C1DE0DAB: 0D63561A33F958A5CCAAAFB1131B4DB320D9DEC80861E29E747F282574425A1AD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA752546FE575EB473F1410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D340B06C327CE4A70E8C3933A4DF4E3C60E0F4E5A0864372BBA77240F636774092580994262E0E8453C1D7E09C32AA3244CCC7531913B8ACF57CD5C72E086E062CD35DA7DC5AF9B58C0729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioja9FuITQvsRq6s5wl8SO6Gg== X-Mailru-Sender: 6CA451E36783D721CBEA96CEA26D325DF4C3EA856622283E4842A7205ED1A108B7CBEF92542CD7C82F97C478340294DCC77752E0C033A69E0F0C7111264B8915FF1320A92A5534336C18EFA0BB12DBB0 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix a segfault in hex() on receiving zeroblob 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: Safin Timur via Tarantool-patches Reply-To: Safin Timur Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This version is much simpler and is quite readable as is. LGTM. Though few unimportant notes... On 30.08.2021 9:20, imeevma@tarantool.org wrote: > This patch fixes a segmentation fault when zeroblob is received by the > SQL built-in HEX() function. > > Closes #6113 > --- > https://github.com/tarantool/tarantool/issues/6113 > https://github.com/tarantool/tarantool/tree/imeevma/gh-6113-fix-hex-segfault-2.8 > > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index b137c6125..3ef31705e 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -1221,15 +1221,21 @@ hexFunc(sql_context * context, int argc, sql_value ** argv) > UNUSED_PARAMETER(argc); > pBlob = mem_as_bin(argv[0]); > n = mem_len_unsafe(argv[0]); > + assert((argv[0]->flags & MEM_Zero) == 0 || > + argv[0]->type == MEM_TYPE_BIN); I believe this is unncessary, as those exactly checks were already done inside of mem_len() > + int zero_len = (argv[0]->flags & MEM_Zero) == 0 ? 0 : argv[0]->u.nZero; > assert(pBlob == mem_as_bin(argv[0])); /* No encoding change */ > z = zHex = contextMalloc(context, ((i64) n) * 2 + 1); Worth to note that here contextMalloc() used to check passed length against SQL_LIMIT_LENGTH, in the newer code this check disappeared. > if (zHex) { > - for (i = 0; i < n; i++, pBlob++) { > + for (i = 0; i < n - zero_len; i++, pBlob++) { > unsigned char c = *pBlob; > *(z++) = hexdigits[(c >> 4) & 0xf]; > *(z++) = hexdigits[c & 0xf]; > } > - *z = 0; > + assert(i == n || (argv[0]->flags & MEM_Zero) != 0); > + assert(n == zero_len + i); > + memset(z, '0', 2 * zero_len); > + z[2 * zero_len] = '\0'; > sql_result_text(context, zHex, n * 2, sql_free); > } > } Regards, Timur