Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Mergen Imeev <imeevma@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix error on copy empty string in mem_copy()
Date: Mon, 30 Aug 2021 23:32:15 +0200	[thread overview]
Message-ID: <d29ecb35-ca5a-6c0d-b525-267068b49651@tarantool.org> (raw)
In-Reply-To: <20210830055706.GA63349@tarantool.org>

Thanks for the fixes!

On 30.08.2021 07:57, Mergen Imeev wrote:
> Thank you for the review! My answers, diff and new patch below.
> 
> On Fri, Aug 27, 2021 at 11:44:23PM +0200, Vladislav Shpilevoy wrote:
>> Thanks for the fixes!
>>
>> See 3 comments below.
>>
>>>     sql: fix error on copy empty string in mem_copy()
>>>     
>>>     This patch fixes the problem with copying an empty string in mem_copy().
>>>     Previously, because the string length was 0, an error was thrown, but
>>>     the diag was not set, which could lead to an error due to an empty diag
>>>     or to a double free.
>>>     
>>>     Closes #6157
>>
>> 1. You also need to add closes 6399, don't you?
>>
> True, thank you. Fixed.

You didn't add it to the changelog. You can use the same file for both
tickets I think.

>>> diff --git a/test/sql-tap/gh-6157-unnecessary-free-on-string.test.lua b/test/sql-tap/gh-6157-unnecessary-free-on-string.test.lua
>>> new file mode 100755
>>> index 000000000..e0c09a325
>>> --- /dev/null
>>> +++ b/test/sql-tap/gh-6157-unnecessary-free-on-string.test.lua
>>> @@ -0,0 +1,18 @@
>>> +#!/usr/bin/env tarantool
>>> +local tap = require('tap')
>>> +local test = tap.test('test wrong error in mem_copy()')
>>> +
>>> +--
>>> +-- Make sure there is no assert due to an incorrectly set error in mem_copy().
>>> +-- How this test works: We have 128 mempool cells in SQL ("lookaside"), and
>>> +-- until those 128 cells are filled in, the error cannot be reproduced. Also, we
>>> +-- have to get '' from somewhere because if we just enter it, it will be of type
>>> +-- STATIC and no memory will be allocated.
>>
>> 3. You mention 128 cells, but I don't see how 128 or something close is used
>> in this test.
>>
> Fixed. Increased number of expressions to 129 and reworked the test-file a bit.

If you say it depends on 128, why did the test fail without the patch even
before you made it use 129 cells?

> diff --git a/test/sql-tap/gh-6157-unnecessary-free-on-string.test.lua b/test/sql-tap/gh-6157-unnecessary-free-on-string.test.lua
> new file mode 100755
> index 000000000..e2d25d7d4
> --- /dev/null
> +++ b/test/sql-tap/gh-6157-unnecessary-free-on-string.test.lua
> @@ -0,0 +1,29 @@
> +#!/usr/bin/env tarantool
> +local test = require("sqltester")
> +test:plan(1)
> +
> +--
> +-- Make sure there is no assert due to an incorrectly set error in mem_copy().
> +-- How this test works: We have 128 mempool cells in SQL ("lookaside"), and
> +-- until those 128 cells are filled in, the error cannot be reproduced. Also, we
> +-- have to get '' from somewhere because if we just enter it, it will be of type
> +-- STATIC and no memory will be allocated.
> +--
> +local s = "NULLIF(SUBSTR('123', 1, 0), NULL)"
> +for i = 1, 7 do s = s..', '..s end
> +s = "SELECT "..s..', '.."NULLIF(SUBSTR('123', 1, 0), NULL)"
> +-- The "s" variable contains 129 expressions.
> +
> +test:do_execsql_test(
> +    "gh-6157", s, {
> +        "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
> +        "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
> +        "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
> +        "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
> +        "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
> +        "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
> +        "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
> +        "", "", ""

Lua has loops. You can use them to avoid copy-paste.

	t = {}
	for i = 1, 129 do table.insert(t, '') end

  reply	other threads:[~2021-08-30 21:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26 11:09 Mergen Imeev via Tarantool-patches
2021-08-26 20:21 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-27 15:22   ` Mergen Imeev via Tarantool-patches
2021-08-27 21:44     ` Vladislav Shpilevoy via Tarantool-patches
2021-08-30  5:57       ` Mergen Imeev via Tarantool-patches
2021-08-30 21:32         ` Vladislav Shpilevoy via Tarantool-patches [this message]
2021-08-31  8:55           ` Mergen Imeev via Tarantool-patches
2021-09-01 21:34             ` Vladislav Shpilevoy via Tarantool-patches
2021-09-02  8:43 Mergen Imeev via Tarantool-patches
2021-09-02  9:15 ` Timur Safin via Tarantool-patches
2021-09-02  9:35   ` Mergen Imeev via Tarantool-patches
2021-09-02  9:17 ` Timur Safin 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=d29ecb35-ca5a-6c0d-b525-267068b49651@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix error on copy empty string in mem_copy()' \
    /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