From: Serge Petrenko <sergepetrenko@tarantool.org> To: vdavydov.dev@gmail.com, tarantool-patches@freelists.org Cc: Serge Petrenko <sergepetrenko@tarantool.org> Subject: [PATCH] sql: fix error handling in sql_analysis_load() Date: Thu, 22 Nov 2018 19:59:03 +0300 [thread overview] Message-ID: <20181122165903.64923-1-sergepetrenko@tarantool.org> (raw) Previously if an error occured in box_index_len() called from sql_analysis_load(), the return code (-1 on error) was cast to uint32_t and used later as size of memory to be allocated. This lead to assertion failures in slab_order() since allocation size was too big. This was discovered during investigation of #3779. Fix error handling and add some error logging. Follow-up #3779 --- https://github.com/tarantool/tarantool/tree/sp/slab-assert-fix https://github.com/tarantool/tarantool/issues/3779 src/box/sql.c | 7 +++++-- src/box/sql/analyze.c | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/box/sql.c b/src/box/sql.c index d7df84874..49e1237d7 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -90,9 +90,12 @@ sql_load_schema() if (stat->def->field_count == 0) return; db->init.busy = 1; - sql_analysis_load(db); - if (db->errCode != SQLITE_OK) + if (sql_analysis_load(db) != SQLITE_OK) { + if(!diag_is_empty(&fiber()->diag)) { + diag_log(); + } panic("failed to initialize SQL subsystem"); + } db->init.busy = 0; } diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c index e786c9019..3f492800c 100644 --- a/src/box/sql/analyze.c +++ b/src/box/sql/analyze.c @@ -1682,7 +1682,9 @@ stat_copy(struct index_stat *dest, const struct index_stat *src) int sql_analysis_load(struct sqlite3 *db) { - uint32_t index_count = box_index_len(BOX_SQL_STAT1_ID, 0); + ssize_t index_count = box_index_len(BOX_SQL_STAT1_ID, 0); + if (index_count < 0) + return SQL_TARANTOOL_ERROR; if (box_txn_begin() != 0) goto fail; size_t stats_size = index_count * sizeof(struct index_stat); -- 2.17.2 (Apple Git-113)
next reply other threads:[~2018-11-22 16:59 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-11-22 16:59 Serge Petrenko [this message] 2018-11-27 10:01 ` Vladimir Davydov
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=20181122165903.64923-1-sergepetrenko@tarantool.org \ --to=sergepetrenko@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH] sql: fix error handling in sql_analysis_load()' \ /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