From 07e99d3b9a3e82b860555b51a5e2e05f9c726d21 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 29 Dec 2021 19:45:58 +0800 Subject: [PATCH] [TS-995](query): validate pTableCheckInfo when querying last/last_row --- src/tsdb/src/tsdbRead.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index be734ce0cc..49837efc5d 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -596,6 +596,12 @@ void tsdbResetQueryHandleForNewTable(TsdbQueryHandleT queryHandle, STsdbQueryCon static int32_t lazyLoadCacheLast(STsdbQueryHandle* pQueryHandle) { STsdbRepo* pRepo = pQueryHandle->pTsdb; + if (!pQueryHandle->pTableCheckInfo) { + tsdbError("%p table check info is NULL", pQueryHandle); + terrno = TSDB_CODE_QRY_APP_ERROR; + return -1; + } + size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo); int32_t code = 0; for (size_t i = 0; i < numOfTables; ++i) { @@ -628,7 +634,9 @@ TsdbQueryHandleT tsdbQueryLastRow(STsdbRepo *tsdb, STsdbQueryCond *pCond, STable return NULL; } - lazyLoadCacheLast(pQueryHandle); + if (lazyLoadCacheLast(pQueryHandle) != TSDB_CODE_SUCCESS) { + return NULL; + } int32_t code = checkForCachedLastRow(pQueryHandle, groupList); if (code != TSDB_CODE_SUCCESS) { // set the numOfTables to be 0 @@ -650,7 +658,9 @@ TsdbQueryHandleT tsdbQueryCacheLast(STsdbRepo *tsdb, STsdbQueryCond *pCond, STab return NULL; } - lazyLoadCacheLast(pQueryHandle); + if (lazyLoadCacheLast(pQueryHandle) != TSDB_CODE_SUCCESS) { + return NULL; + } int32_t code = checkForCachedLast(pQueryHandle); if (code != TSDB_CODE_SUCCESS) { // set the numOfTables to be 0 -- GitLab