From 27300117d0ef43ca57641304a8715a456f9e69b3 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 6 Jul 2022 13:49:25 +0800 Subject: [PATCH] fix(query): fix substr parameter check TD-16322 --- source/libs/function/src/builtins.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index d9a05973ce..22438e6939 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -1615,26 +1615,27 @@ static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) } SExprNode* pPara0 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); - SExprNode* p1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 1); + SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 1); - uint8_t para1Type = p1->resType.type; - if (!IS_VAR_DATA_TYPE(pPara0->resType.type) || !IS_INTEGER_TYPE(para1Type)) { + uint8_t para0Type = pPara0->resType.type; + uint8_t para1Type = pPara1->resType.type; + if (!IS_VAR_DATA_TYPE(para0Type) || !IS_INTEGER_TYPE(para1Type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - if (((SValueNode*)p1)->datum.i < 1) { + if (((SValueNode*)pPara1)->datum.i == 0) { return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); } if (3 == numOfParams) { - SExprNode* p2 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 2); - uint8_t para2Type = p2->resType.type; + SExprNode* pPara2 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 2); + uint8_t para2Type = pPara2->resType.type; if (!IS_INTEGER_TYPE(para2Type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - int64_t v = ((SValueNode*)p1)->datum.i; - if (v < 0 || v > INT16_MAX) { + int64_t v = ((SValueNode*)pPara2)->datum.i; + if (v < 0) { return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); } }