From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp51.i.mail.ru (smtp51.i.mail.ru [94.100.177.111]) (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 5E3314696C0 for ; Fri, 5 Jun 2020 02:43:21 +0300 (MSK) From: Vladislav Shpilevoy Date: Fri, 5 Jun 2020 01:43:07 +0200 Message-Id: <0fee78a0b7501bbf74e76e06d7662b78188aa061.1591313754.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 10/11] sql: fix usage of not initialized index_stat List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, tsafin@tarantool.org, alyapunov@tarantool.org Query planner uses a temporary index definition object 'to represent the primary key index'. Whatever real purpose of this index_def is (query planner wasn't changed since SQLite merge, and may be broken), its opts.stat field pointed at a partially initialized index_stat structure. Which is supposed to be used by the planner to make decisions such as search by which index would be the optimal. The patch initializes the statistics with 0. Part of #4609 --- src/box/sql/where.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/box/sql/where.c b/src/box/sql/where.c index 7ec43e184..e9e936856 100644 --- a/src/box/sql/where.c +++ b/src/box/sql/where.c @@ -2794,9 +2794,9 @@ tnt_error: fake_index->iid = UINT32_MAX; int size = sizeof(struct index_stat) + sizeof(log_est_t) * 2; - struct index_stat *stat = (struct index_stat *) malloc(size); + struct index_stat *stat = (struct index_stat *) calloc(1, size); if (stat == NULL) { - diag_set(OutOfMemory, size, "malloc", "stat"); + diag_set(OutOfMemory, size, "calloc", "stat"); goto tnt_error; } stat->tuple_log_est = (log_est_t *) ((char *) (stat + 1)); -- 2.21.1 (Apple Git-122.3)