From c96f11e808742f4e2ad796cfbb9b6cb39db099fb Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 9 Jun 2020 10:35:07 +0000 Subject: [PATCH] [TD_543] fix coverity scan issues in dnode module --- src/dnode/src/dnodePeer.c | 11 ++++++----- src/dnode/src/dnodeShell.c | 14 ++++++++------ src/dnode/src/dnodeSystem.c | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/dnode/src/dnodePeer.c b/src/dnode/src/dnodePeer.c index eb017c335e..851e895f83 100644 --- a/src/dnode/src/dnodePeer.c +++ b/src/dnode/src/dnodePeer.c @@ -83,11 +83,12 @@ void dnodeCleanupServer() { } static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { - SRpcMsg rspMsg; - rspMsg.handle = pMsg->handle; - rspMsg.pCont = NULL; - rspMsg.contLen = 0; - + SRpcMsg rspMsg = { + .handle = pMsg->handle, + .pCont = NULL, + .contLen = 0 + }; + if (dnodeGetRunStatus() != TSDB_DNODE_RUN_STATUS_RUNING) { rspMsg.code = TSDB_CODE_RPC_NOT_READY; rpcSendResponse(&rspMsg); diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index 8eba1f3775..95e4c49422 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -19,6 +19,7 @@ #include "taosdef.h" #include "taosmsg.h" #include "tglobal.h" +#include "tutil.h" #include "http.h" #include "mnode.h" #include "dnode.h" @@ -108,10 +109,11 @@ void dnodeCleanupShell() { } void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { - SRpcMsg rpcMsg; - rpcMsg.handle = pMsg->handle; - rpcMsg.pCont = NULL; - rpcMsg.contLen = 0; + SRpcMsg rpcMsg = { + .handle = pMsg->handle, + .pCont = NULL, + .contLen = 0 + }; if (dnodeGetRunStatus() != TSDB_DNODE_RUN_STATUS_RUNING) { dError("RPC %p, shell msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]); @@ -143,7 +145,7 @@ static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char if (code != TSDB_CODE_RPC_NOT_READY) return code; SDMAuthMsg *pMsg = rpcMallocCont(sizeof(SDMAuthMsg)); - strcpy(pMsg->user, user); + tstrncpy(pMsg->user, user, TSDB_USER_LEN); SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pMsg; @@ -201,7 +203,7 @@ void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t sid) { int16_t numOfTags = htons(pTable->numOfTags); int32_t sid = htonl(pTable->sid); uint64_t uid = htobe64(pTable->uid); - dPrint("table:%s, numOfColumns:%d numOfTags:%d sid:%d uid:%d", pTable->tableId, numOfColumns, numOfTags, sid, uid); + dPrint("table:%s, numOfColumns:%d numOfTags:%d sid:%d uid:" PRIu64, pTable->tableId, numOfColumns, numOfTags, sid, uid); return rpcRsp.pCont; } diff --git a/src/dnode/src/dnodeSystem.c b/src/dnode/src/dnodeSystem.c index 0a983362c2..3efa1c728d 100644 --- a/src/dnode/src/dnodeSystem.c +++ b/src/dnode/src/dnodeSystem.c @@ -33,7 +33,7 @@ int32_t main(int32_t argc, char *argv[]) { printf("config file path overflow"); exit(EXIT_FAILURE); } - strcpy(configDir, argv[i]); + tstrncpy(configDir, argv[i], TSDB_FILENAME_LEN); } else { printf("'-c' requires a parameter, default:%s\n", configDir); exit(EXIT_FAILURE);