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 26C016EC55; Thu, 26 Aug 2021 23:31:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 26C016EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1630009917; bh=b2/FN5Z6x517o64bZNLeWR20Tqtul0tL1MEbnsdiu/c=; 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=Einj31F2mpjQL+PA+u+v0APtc04H+/fVy1A2xIM2dq+BQpFpe9avxRwkxL0sHJv+o elhzmqTg0XReSh7AlxQpwCQre+xArwiHYW5pM7RWnkdp3slZeItY4M6nQkEvK8tI/W g5hmM6e2twV0Ao/EA9zmdSDDG+lwLUW1+a0AF9WI= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [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 679196EC55 for ; Thu, 26 Aug 2021 23:31:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 679196EC55 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1mJM2U-0002tl-NB; Thu, 26 Aug 2021 23:31:55 +0300 To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <866533cf6634609e69fdf734fd2a124361117a5f.1629976189.git.imeevma@gmail.com> Message-ID: <781509c4-6531-1f3b-0ff2-cc95a4bf489c@tarantool.org> Date: Thu, 26 Aug 2021 22:31:53 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <866533cf6634609e69fdf734fd2a124361117a5f.1629976189.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9F9A2272A1D086A28553D1D5C4B4124EF182A05F5380850406B9FE4B7BAA1B8B50CCF9C867732DDCFB147E873016319093C0C688CA14C9630 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE78E8764B5BC580342EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378997215BCAA11D778638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8246FA9AA8710A85CFB85DE15102D8B8A117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BF1175FABE1C0F9B6A471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C468D16C903838CAB43847C11F186F3C59DAA53EE0834AAEE X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505BFD030A668ACDA916973B4E33CF7B03D X-C1DE0DAB: 0D63561A33F958A50B6D1C129AFF7317A6E1DEDD5515861F8A78FB64C1CA4F1AD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA756665624D6DDF07B5410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D349C39CCCDAABCB54B9EF2506364A8A96713442B3B11D76564F3768C09D43DE729969871E787EBD03E1D7E09C32AA3244C51C25CBEB08866CF84243FD868AAA826795D98D676DD64D0729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj+bzRAXO2P1SaMAKzPKWFag== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DCC9737DB164180FE59439821AC533B453841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B 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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the patch! > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index b137c6125..d182bb313 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -1221,14 +1221,22 @@ 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); > + 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); > 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]; > } > + for (; i < n; ++i) { > + assert((argv[0]->flags & MEM_Zero) != 0); 1. This assert can be out of the loop. It does not depend on z or i. 2. The loop could be replaced with memset(). > + *(z++) = '0'; > + *(z++) = '0'; > + }