From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 0DDE62A1A4 for ; Tue, 23 Apr 2019 06:20:19 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7grNAlZUFy8f for ; Tue, 23 Apr 2019 06:20:18 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id C2DD72A1BE for ; Tue, 23 Apr 2019 06:20:18 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v1 1/1] box: fix empty tuple invalid update References: <8d2b8471b96efc182d82301808fe9ffec394ee5f.1556007413.git.kshcherbatov@tarantool.org> <231e1c1c-d33a-2132-3602-e37fa2010b8d@tarantool.org> From: Vladislav Shpilevoy Message-ID: <5aa0df3b-3675-b49f-2aa2-27b55b10a261@tarantool.org> Date: Tue, 23 Apr 2019 13:20:15 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: Kirill Shcherbatov , tarantool-patches@freelists.org, Kirill Yukhin LGTM. On 23/04/2019 13:17, Kirill Shcherbatov wrote: > > A few lines above you allocate struct update_field, which >> is unused when field == end. Please, move this check before >> update->alloc(). > You are right. Thank you. > ==================================== > The tuple:update() used to work incorrectly in case of empty > tuple produced with box.tuple.new{} because update_create_rope > unconditionally initialized a new rope with [tuple_data, > mp_next(tuple_data)] field that might not exists. > > Closes #4041 > --- > src/box/tuple_update.c | 3 +++ > test/box/tuple.result | 21 +++++++++++++++++++++ > test/box/tuple.test.lua | 10 ++++++++++ > 3 files changed, 34 insertions(+) > > diff --git a/src/box/tuple_update.c b/src/box/tuple_update.c > index 01c55fb1a..b879d50f9 100644 > --- a/src/box/tuple_update.c > +++ b/src/box/tuple_update.c > @@ -826,6 +826,9 @@ update_create_rope(struct tuple_update *update, const char *tuple_data, > region_alloc_free_stub, update->alloc_ctx); > if (update->rope == NULL) > return -1; > + if (tuple_data == tuple_data_end) > + return 0; > + > /* Initialize the rope with the old tuple. */ > > struct update_field *first = (struct update_field *) > diff --git a/test/box/tuple.result b/test/box/tuple.result > index 82ad8404d..2561ebc35 100644 > --- a/test/box/tuple.result > +++ b/test/box/tuple.result > @@ -859,6 +859,27 @@ t > t = nil > --- > ... > +-- > +-- gh-4041: Invalid field on empty tuple update. > +-- > +t = box.tuple.new{} > +--- > +... > +t:update({{'=', 1, 1}}) > +--- > +- [1] > +... > +t:upsert({{'=', 1, 1}}) > +--- > +- [1] > +... > +t:update({{'+', 1, 1}}) > +--- > +- error: Field 1 was not found in the tuple > +... > +t = nil > +--- > +... > -------------------------------------------------------------------------------- > -- test msgpack.encode + tuple > -------------------------------------------------------------------------------- > diff --git a/test/box/tuple.test.lua b/test/box/tuple.test.lua > index 8030b0884..b0a4ab173 100644 > --- a/test/box/tuple.test.lua > +++ b/test/box/tuple.test.lua > @@ -270,6 +270,16 @@ t = box.tuple.new(require('yaml').decode("[17711728, {1000: 'xxx'}]")) > t:update({{'=', 2, t[2]}}) > t > t = nil > + > +-- > +-- gh-4041: Invalid field on empty tuple update. > +-- > +t = box.tuple.new{} > +t:update({{'=', 1, 1}}) > +t:upsert({{'=', 1, 1}}) > +t:update({{'+', 1, 1}}) > +t = nil > + > -------------------------------------------------------------------------------- > -- test msgpack.encode + tuple > -------------------------------------------------------------------------------- > -- > 2.21.0 >