diff --git a/include/util/tutil.h b/include/util/tutil.h index 05a2397139..0e79480bfe 100644 --- a/include/util/tutil.h +++ b/include/util/tutil.h @@ -157,18 +157,18 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen, return (terrno = (code)); \ } while (0) -#define TAOS_CHECK_RETURN(CMD) \ - do { \ - int32_t code = (CMD); \ +#define TAOS_CHECK_RETURN(CMD) \ + do { \ + int32_t code = (CMD); \ if (code != TSDB_CODE_SUCCESS) { \ - TAOS_RETURN(code); \ - } \ + TAOS_RETURN(code); \ + } \ } while (0) #define TAOS_CHECK_GOTO(CMD, LINO, LABEL) \ do { \ code = (CMD); \ - if (code != TSDB_CODE_SUCCESS) { \ + if (code != TSDB_CODE_SUCCESS) { \ if (LINO) { \ *((int32_t *)(LINO)) = __LINE__; \ } \ diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c index 93b6d976c2..eee6ab3a41 100644 --- a/source/dnode/mgmt/node_util/src/dmFile.c +++ b/source/dnode/mgmt/node_util/src/dmFile.c @@ -429,9 +429,7 @@ int32_t dmUpdateEncryptKey(char *key, bool toLogFile) { } } - if ((code = tGetMachineId(&machineId)) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(tGetMachineId(&machineId), &lino, _OVER); TAOS_CHECK_GOTO(generateEncryptCode(key, machineId, &encryptCode), &lino, _OVER); diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 387fcb90bc..f7b509b1cc 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -229,26 +229,23 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { SUserObj *pUser = NULL; SDbObj *pDb = NULL; SConnObj *pConn = NULL; - int32_t code = -1; + int32_t code = 0; SConnectReq connReq = {0}; char ip[24] = {0}; const STraceId *trace = &pReq->info.traceId; if ((code = tDeserializeSConnectReq(pReq->pCont, pReq->contLen, &connReq)) != 0) { - terrno = (-1 == code ? TSDB_CODE_INVALID_MSG : code); goto _OVER; } if ((code = taosCheckVersionCompatibleFromStr(connReq.sVer, version, 3)) != 0) { mGError("version not compatible. client version: %s, server version: %s", connReq.sVer, version); - terrno = code; goto _OVER; } - code = -1; taosIp2String(pReq->info.conn.clientIp, ip); - if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONNECT) != 0) { - mGError("user:%s, failed to login from %s since %s", pReq->info.conn.user, ip, terrstr()); + if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONNECT)) != 0) { + mGError("user:%s, failed to login from %s since %s", pReq->info.conn.user, ip, tstrerror(code)); goto _OVER; } @@ -271,22 +268,22 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { if (pDb == NULL) { if (0 != strcmp(connReq.db, TSDB_INFORMATION_SCHEMA_DB) && (0 != strcmp(connReq.db, TSDB_PERFORMANCE_SCHEMA_DB))) { - terrno = TSDB_CODE_MND_DB_NOT_EXIST; + code = TSDB_CODE_MND_DB_NOT_EXIST; mGError("user:%s, failed to login from %s while use db:%s since %s", pReq->info.conn.user, ip, connReq.db, - terrstr()); + tstrerror(code)); goto _OVER; } } - if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_READ_OR_WRITE_DB, pDb) != 0) { - goto _OVER; - } + TAOS_CHECK_GOTO(mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_READ_OR_WRITE_DB, pDb), NULL, _OVER); } pConn = mndCreateConn(pMnode, pReq->info.conn.user, connReq.connType, pReq->info.conn.clientIp, pReq->info.conn.clientPort, connReq.pid, connReq.app, connReq.startTime); if (pConn == NULL) { - mGError("user:%s, failed to login from %s while create connection since %s", pReq->info.conn.user, ip, terrstr()); + code = terrno; + mGError("user:%s, failed to login from %s while create connection since %s", pReq->info.conn.user, ip, + tstrerror(code)); goto _OVER; } @@ -316,10 +313,19 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { mndGetMnodeEpSet(pMnode, &connectRsp.epSet); int32_t contLen = tSerializeSConnectRsp(NULL, 0, &connectRsp); - if (contLen < 0) goto _OVER; + if (contLen < 0) { + TAOS_CHECK_GOTO(contLen, NULL, _OVER); + } void *pRsp = rpcMallocCont(contLen); - if (pRsp == NULL) goto _OVER; - tSerializeSConnectRsp(pRsp, contLen, &connectRsp); + if (pRsp == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER); + } + + contLen = tSerializeSConnectRsp(pRsp, contLen, &connectRsp); + if (contLen < 0) { + rpcFreeCont(pRsp); + TAOS_CHECK_GOTO(contLen, NULL, _OVER); + } pReq->info.rspLen = contLen; pReq->info.rsp = pRsp; @@ -339,7 +345,7 @@ _OVER: mndReleaseDb(pMnode, pDb); mndReleaseConn(pMnode, pConn, true); - return code; + TAOS_RETURN(code); } static int32_t mndSaveQueryList(SConnObj *pConn, SQueryHbReqBasic *pBasic) { @@ -656,6 +662,7 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) { int32_t code = 0; + int32_t lino = 0; SMnode *pMnode = pReq->info.node; SClientHbBatchReq batchReq = {0}; @@ -675,6 +682,9 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) { SClientHbBatchRsp batchRsp = {0}; batchRsp.svrTimestamp = taosGetTimestampSec(); batchRsp.rsps = taosArrayInit(0, sizeof(SClientHbRsp)); + if (batchRsp.rsps == NULL) { + TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + } batchRsp.monitorParas.tsEnableMonitor = tsEnableMonitor; batchRsp.monitorParas.tsMonitorInterval = tsMonitorInterval; batchRsp.monitorParas.tsSlowLogThreshold = tsSlowLogThreshold; @@ -687,7 +697,7 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) { for (int i = 0; i < sz; i++) { SClientHbReq *pHbReq = taosArrayGet(batchReq.reqs, i); if (pHbReq->connKey.connType == CONN_TYPE__QUERY) { - mndProcessQueryHeartBeat(pMnode, pReq, pHbReq, &batchRsp, &obj); + TAOS_CHECK_EXIT(mndProcessQueryHeartBeat(pMnode, pReq, pHbReq, &batchRsp, &obj)); } else if (pHbReq->connKey.connType == CONN_TYPE__TMQ) { SClientHbRsp *pRsp = mndMqHbBuildRsp(pMnode, pHbReq); if (pRsp != NULL) { @@ -699,12 +709,22 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) { taosArrayDestroyEx(batchReq.reqs, tFreeClientHbReq); int32_t tlen = tSerializeSClientHbBatchRsp(NULL, 0, &batchRsp); - void *buf = rpcMallocCont(tlen); - tSerializeSClientHbBatchRsp(buf, tlen, &batchRsp); - - tFreeClientHbBatchRsp(&batchRsp); + if (tlen < 0) { + TAOS_CHECK_EXIT(tlen); + } + void *buf = rpcMallocCont(tlen); + if (!buf) { + TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + } + tlen = tSerializeSClientHbBatchRsp(buf, tlen, &batchRsp); + if (tlen < 0) { + rpcFreeCont(buf); + TAOS_CHECK_EXIT(tlen); + } pReq->info.rspLen = tlen; pReq->info.rsp = buf; +_exit: + tFreeClientHbBatchRsp(&batchRsp); taosArrayDestroy(obj.pQnodeList); @@ -771,24 +791,31 @@ static int32_t mndProcessKillConnReq(SRpcMsg *pReq) { } static int32_t mndProcessSvrVerReq(SRpcMsg *pReq) { - int32_t code = -1; + int32_t code = 0; + int32_t lino = 0; SServerVerRsp rsp = {0}; tstrncpy(rsp.ver, version, sizeof(rsp.ver)); int32_t contLen = tSerializeSServerVerRsp(NULL, 0, &rsp); - if (contLen < 0) goto _over; + if (contLen < 0) { + TAOS_CHECK_EXIT(contLen); + } void *pRsp = rpcMallocCont(contLen); - if (pRsp == NULL) goto _over; - tSerializeSServerVerRsp(pRsp, contLen, &rsp); + if (pRsp == NULL) { + TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + } + contLen = tSerializeSServerVerRsp(pRsp, contLen, &rsp); + if (contLen < 0) { + rpcFreeCont(pRsp); + TAOS_CHECK_EXIT(contLen); + } pReq->info.rspLen = contLen; pReq->info.rsp = pRsp; - code = 0; +_exit: -_over: - - return code; + TAOS_RETURN(code); } static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 0e4730a731..f05baf25bd 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -1958,8 +1958,7 @@ int32_t mndProcesSRetrieveIpWhiteReq(SRpcMsg *pReq) { len = tSerializeSUpdateIpWhite(NULL, 0, &ipWhite); if (len < 0) { - code = TSDB_CODE_OUT_OF_MEMORY; - TAOS_CHECK_GOTO(code, &lino, _OVER); + TAOS_CHECK_GOTO(len, &lino, _OVER); } pRsp = rpcMallocCont(len); @@ -1968,8 +1967,7 @@ int32_t mndProcesSRetrieveIpWhiteReq(SRpcMsg *pReq) { } len = tSerializeSUpdateIpWhite(pRsp, len, &ipWhite); if (len < 0) { - code = TSDB_CODE_OUT_OF_MEMORY; - TAOS_CHECK_GOTO(code, &lino, _OVER); + TAOS_CHECK_GOTO(len, &lino, _OVER); } _OVER: @@ -2597,7 +2595,10 @@ static int32_t mndProcessGetUserAuthReq(SRpcMsg *pReq) { TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); } - TAOS_CHECK_EXIT(tSerializeSGetUserAuthRsp(pRsp, contLen, &authRsp)); + contLen =tSerializeSGetUserAuthRsp(pRsp, contLen, &authRsp); + if(contLen < 0) { + TAOS_CHECK_EXIT(contLen); + } _exit: mndReleaseUser(pMnode, pUser); @@ -3190,14 +3191,17 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_ } rspLen = tSerializeSUserAuthBatchRsp(NULL, 0, &batchRsp); - if (rspLen <= 0) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + if (rspLen < 0) { + TAOS_CHECK_GOTO(rspLen, &lino, _OVER); } pRsp = taosMemoryMalloc(rspLen); if (pRsp == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); } - TAOS_CHECK_GOTO(tSerializeSUserAuthBatchRsp(pRsp, rspLen, &batchRsp), &lino, _OVER); + rspLen = tSerializeSUserAuthBatchRsp(pRsp, rspLen, &batchRsp); + if (rspLen < 0) { + TAOS_CHECK_GOTO(rspLen, &lino, _OVER); + } _OVER: tFreeSUserAuthBatchRsp(&batchRsp); if (code < 0) {