From 04af5f4b944e9580b0bdfa73fdd7800d90682859 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Tue, 19 Nov 2024 19:38:40 +0800 Subject: [PATCH] enh: check param --- source/libs/executor/inc/operator.h | 8 ++++++++ source/libs/executor/src/aggregateoperator.c | 8 ++++++++ source/libs/executor/src/anomalywindowoperator.c | 5 +++++ source/libs/executor/src/executorInt.c | 1 + 4 files changed, 22 insertions(+) diff --git a/source/libs/executor/inc/operator.h b/source/libs/executor/inc/operator.h index f2e542e7cd..5ceedbe542 100644 --- a/source/libs/executor/inc/operator.h +++ b/source/libs/executor/inc/operator.h @@ -202,6 +202,14 @@ void * getOperatorParam(int32_t opType, SOperatorParam* param, int32_t i void doKeepTuple(SWindowRowsSup* pRowSup, int64_t ts, uint64_t groupId); void doKeepNewWindowStartInfo(SWindowRowsSup* pRowSup, const int64_t* tsList, int32_t rowIndex, uint64_t groupId); +#define CHECK_CONDITION_FAILED(c) \ + do { \ + if (!(c)) { \ + qError("function:%s condition failed, Line:%d", __FUNCTION__, __LINE__); \ + return TSDB_CODE_APP_ERROR; \ + } \ + } while (0) + #ifdef __cplusplus } #endif diff --git a/source/libs/executor/src/aggregateoperator.c b/source/libs/executor/src/aggregateoperator.c index 829ca6da50..b71ed5ee26 100644 --- a/source/libs/executor/src/aggregateoperator.c +++ b/source/libs/executor/src/aggregateoperator.c @@ -184,6 +184,10 @@ static bool nextGroupedResult(SOperatorInfo* pOperator) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SAggOperatorInfo* pAggInfo = pOperator->info; + if(!pAggInfo) { + qError("function:%s, pAggInfo is NULL", __func__); + return false; + } if (pOperator->blocking && pAggInfo->hasValidBlock) { return false; } @@ -333,6 +337,10 @@ static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) { int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) { int32_t code = TSDB_CODE_SUCCESS; + if (pOperator || (pOperator->exprSupp.numOfExprs > 0 && pCtx == NULL)) { + qError("%s failed at line %d since pCtx is NULL.", __func__, __LINE__); + return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + } for (int32_t k = 0; k < pOperator->exprSupp.numOfExprs; ++k) { if (functionNeedToExecute(&pCtx[k])) { // todo add a dummy function to avoid process check diff --git a/source/libs/executor/src/anomalywindowoperator.c b/source/libs/executor/src/anomalywindowoperator.c index 94cc5d9129..b678030a1c 100644 --- a/source/libs/executor/src/anomalywindowoperator.c +++ b/source/libs/executor/src/anomalywindowoperator.c @@ -171,6 +171,10 @@ _error: } static int32_t anomalyAggregateNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { + CHECK_CONDITION_FAILED(pOperator != NULL); + CHECK_CONDITION_FAILED(ppRes != NULL); + CHECK_CONDITION_FAILED(pOperator->info != NULL); + CHECK_CONDITION_FAILED(pOperator->pTaskInfo != NULL); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; SAnomalyWindowOperatorInfo* pInfo = pOperator->info; @@ -181,6 +185,7 @@ static int32_t anomalyAggregateNext(SOperatorInfo* pOperator, SSDataBlock** ppRe int64_t st = taosGetTimestampUs(); int32_t numOfBlocks = taosArrayGetSize(pSupp->blocks); + CHECK_CONDITION_FAILED(pRes != NULL); blockDataCleanup(pRes); while (1) { diff --git a/source/libs/executor/src/executorInt.c b/source/libs/executor/src/executorInt.c index 1b823bf69d..4a1d26d875 100644 --- a/source/libs/executor/src/executorInt.c +++ b/source/libs/executor/src/executorInt.c @@ -255,6 +255,7 @@ static int32_t doSetInputDataBlockInfo(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; SqlFunctionCtx* pCtx = pExprSup->pCtx; + CHECK_CONDITION_FAILED(pExprSup->numOfExprs <= 0 || pCtx != NULL); for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) { pCtx[i].order = order; pCtx[i].input.numOfRows = pBlock->info.rows;