Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] vinyl: fix passing uninitialized parameter to vy_page_find_key()
Date: Tue, 16 Jun 2020 23:21:42 +0000	[thread overview]
Message-ID: <20200616232142.GB9358@tarantool.org> (raw)
In-Reply-To: <e42b86c4-636e-757b-d643-db219b89cc9b@tarantool.org>

On 17 Jun 01:10, Vladislav Shpilevoy wrote:
> Hi! Thanks for the patch!
> 
> On 15/06/2020 20:42, Nikita Pettik wrote:
> > vy_page_find_key() assumes that equal_key parameter is initialized since
> > it is used unconditionally. There are several places where
> > vy_page_find_key() is called:
> > 
> > - vy_slice_stream_search() calls vy_page_find_key();
> > - vy_run_iterator_read() calls vy_run_iterator_load_page(),
> > which in turn calls vy_page_find_key();
> > - vy_run_iterator_search() also calls vy_run_iterator_load_page().
> > 
> > First two fixes are obvious - lifespan of parameter passed to
> > *_find_key() is clear and restricted by caller. In the last case
> > firstly vy_page_find_key() is called, but equal_key output value is not
> > used. Then it is re-assigned with task->equal_found which is the result
> > of another on vy_page_find_key() invocation in vy_page_read_cb. So it is
> > safe to initialize equal_found parameter with 'false' value as well.
> 
> You said that in the last case vy_page_find_key() is called first, but
> I don't see where. vy_run_iterator_search() does not call vy_page_find_key().

vy_run_iterator_search()
  --> vy_run_iterator_load_page()
        --> 1021 vy_page_find_key()
        --> 1051 task->equal_found = false;
        --> 1056 *equal_found = task->equal_found;

Also see b907231713a75d716793505ad727ecea9415d774
Analogue of equal_key was equal_in_page which was 'false' by default.
It's pretty sad that tests do not cover this path. Could you please
file an issue to provide proper test? I'll try to come up with test some day.
 
> What is bothering me, is that this not initialized bool was almost always
> true on my machine (due to not-zero garbage). I changed it to true, and
> the tests passed. Reverted back to false - passed as well.
> 
> So there either is missing a good test on that, or vy_run_iterator_load_page()
> does not need the parameter 'bool *equal_found'. Because its input and
> output values don't matter. In both invocation places this parameter does
> not affect anything.
> 
> > diff --git a/src/box/vy_run.c b/src/box/vy_run.c
> > index 54cf028d0..db4565954 100644
> > --- a/src/box/vy_run.c
> > +++ b/src/box/vy_run.c
> > @@ -1129,7 +1129,7 @@ vy_run_iterator_search(struct vy_run_iterator *itr,
> >  					       equal_key);
> >  	if (pos->page_no == itr->slice->run->info.page_count)
> >  		return 1;
> > -	bool equal_in_page;
> > +	bool equal_in_page = false;
> 
> This I changed to true, and all the tests passed.

  reply	other threads:[~2020-06-16 23:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15 18:42 Nikita Pettik
2020-06-16 23:10 ` Vladislav Shpilevoy
2020-06-16 23:21   ` Nikita Pettik [this message]
2020-06-17 21:56     ` Vladislav Shpilevoy
2020-06-22  0:02       ` Nikita Pettik
2020-06-22 22:54         ` Vladislav Shpilevoy
2020-06-23  0:08           ` Nikita Pettik

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=20200616232142.GB9358@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] vinyl: fix passing uninitialized parameter to vy_page_find_key()' \
    /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