Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] vinyl: fix passing uninitialized parameter to vy_page_find_key()
@ 2020-06-15 18:42 Nikita Pettik
  2020-06-16 23:10 ` Vladislav Shpilevoy
  0 siblings, 1 reply; 7+ messages in thread
From: Nikita Pettik @ 2020-06-15 18:42 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy

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.

Closes #5078
---
Branch: https://github.com/tarantool/tarantool/tree/np/gh-5078-uninit-var-sanitizer
Issue: https://github.com/tarantool/tarantool/issues/5078

 src/box/vy_run.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

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
@@ -1095,7 +1095,7 @@ vy_run_iterator_read(struct vy_run_iterator *itr,
 		     struct vy_entry *ret)
 {
 	struct vy_page *page;
-	bool equal_found;
+	bool equal_found = false;
 	uint32_t pos_in_page;
 	int rc = vy_run_iterator_load_page(itr, pos.page_no, vy_entry_none(),
 					   ITER_GE, &page, &pos_in_page,
@@ -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;
 	struct vy_page *page;
 	int rc = vy_run_iterator_load_page(itr, pos->page_no, key,
 					   iterator_type, &page,
@@ -2615,7 +2615,7 @@ vy_slice_stream_search(struct vy_stmt_stream *virt_stream)
 	if (vy_slice_stream_read_page(stream) != 0)
 		return -1;
 
-	bool unused;
+	bool unused = false;
 	stream->pos_in_page = vy_page_find_key(stream->page,
 					       stream->slice->begin,
 					       stream->cmp_def,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-06-23  0:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 18:42 [Tarantool-patches] [PATCH] vinyl: fix passing uninitialized parameter to vy_page_find_key() Nikita Pettik
2020-06-16 23:10 ` Vladislav Shpilevoy
2020-06-16 23:21   ` Nikita Pettik
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox