diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index e1f17b09a98a53f570f581f5164d684c75a92f47..0e57c7317ee6932133414a3e610644d503caa0de 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -31,7 +31,7 @@ extern "C" { do { \ VarDataLenT __len = strlen(str); \ *(VarDataLenT *)(x) = __len; \ - strncpy(varDataVal(x), (str), __len); \ + memcpy(varDataVal(x), (str), __len); \ } while (0); #define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) \ @@ -43,7 +43,7 @@ extern "C" { #define STR_WITH_SIZE_TO_VARSTR(x, str, _size) \ do { \ *(VarDataLenT *)(x) = (_size); \ - strncpy(varDataVal(x), (str), (_size)); \ + memcpy(varDataVal(x), (str), (_size)); \ } while (0); // ----------------- TSDB COLUMN DEFINITION diff --git a/src/dnode/src/dnodePeer.c b/src/dnode/src/dnodePeer.c index eb017c335ea1fa2b04a73a558d2796f4c4066a71..851e895f8373098382c120ec6cf8c31149a8af6b 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 8eba1f3775fb91c97b208ba185c0094150fddfd2..117059ae668dd4e5812e63f2c30c5300a2b37228 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 0a983362c2d65c5b57f382a379b1578612ad0f05..3efa1c728d8b6eac72ea2724df918dc4340f22c2 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); diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index c80dc3036f786f33b3065c8e7da796a42bfe4059..3666d61adc8b2c10b1c7615422b4db7031bc1251 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -882,7 +882,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { } if (pDb->cfg.replications - replications >= 2) { - mError("db:%s, replica number can't change from 3 to 1", pDb->name, replications); + mError("db:%s, replica number can't change from %d to %d", pDb->name, pDb->cfg.replications, replications); terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } } diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 6fd565b5e6a42c757cb1f90603597ae0afabd733..d2af86badb2869b47501a1fdc47e464554b2e83f 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -90,7 +90,7 @@ static int32_t mnodeDnodeActionDelete(SSdbOper *pOper) { static int32_t mnodeDnodeActionUpdate(SSdbOper *pOper) { SDnodeObj *pDnode = pOper->pObj; SDnodeObj *pSaved = mnodeGetDnode(pDnode->dnodeId); - if (pDnode != pSaved) { + if (pDnode != pSaved && pDnode != NULL && pSaved != NULL) { memcpy(pSaved, pDnode, pOper->rowSize); free(pDnode); } @@ -237,7 +237,9 @@ void mnodeUpdateDnode(SDnodeObj *pDnode) { .pObj = pDnode }; - sdbUpdateRow(&oper); + if (sdbUpdateRow(&oper) != 0) { + mError("dnodeId:%d, failed update", pDnode->dnodeId); + } } static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) { @@ -383,7 +385,7 @@ static int32_t mnodeCreateDnode(char *ep) { pDnode->createdTime = taosGetTimestampMs(); pDnode->status = TAOS_DN_STATUS_OFFLINE; pDnode->totalVnodes = TSDB_INVALID_VNODE_NUM; - strcpy(pDnode->dnodeEp, ep); + tstrncpy(pDnode->dnodeEp, ep, TSDB_EP_LEN); taosGetFqdnPortFromEp(ep, pDnode->dnodeFqdn, &pDnode->dnodePort); SSdbOper oper = { diff --git a/src/mnode/src/mnodeMain.c b/src/mnode/src/mnodeMain.c index 57bb1b2bac5c0293aabec3e81c74d8661a89fd00..96dc70078315ba3ab088fb201088189853f6ec54 100644 --- a/src/mnode/src/mnodeMain.c +++ b/src/mnode/src/mnodeMain.c @@ -134,8 +134,12 @@ void mnodeStopSystem() { } mnodeCleanupSystem(); - mPrint("mnode file is removed"); - remove(tsMnodeDir); + + if (remove(tsMnodeDir) != 0) { + mPrint("failed to remove mnode file, reason:%s", strerror(errno)); + } else { + mPrint("mnode file is removed"); + } } static void mnodeInitTimer() { diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index 85999f80e7e3e92daf0878d7643127c2771d7e34..bfb92096ecf84ecf4b8afcd77d83ec389468567d 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -97,7 +97,7 @@ SConnObj *mnodeCreateConn(char *user, uint32_t ip, uint16_t port) { .connId = connId, .stime = taosGetTimestampMs() }; - strcpy(connObj.user, user); + tstrncpy(connObj.user, user, TSDB_USER_LEN); char key[10]; sprintf(key, "%u", connId); diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 8d7482784124264035ed9a2c93afb0f41c93f288..a13c6ca129c3c8b2bf58b73958d925657f655cbd 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -30,6 +30,8 @@ #include "mnodeDnode.h" #include "mnodeSdb.h" +#define SDB_TABLE_LEN 12 + typedef enum { SDB_ACTION_INSERT, SDB_ACTION_DELETE, @@ -43,7 +45,7 @@ typedef enum { } ESdbStatus; typedef struct _SSdbTable { - char tableName[TSDB_DB_NAME_LEN]; + char tableName[SDB_TABLE_LEN]; ESdbTable tableId; ESdbKey keyType; int32_t hashSessions; @@ -174,10 +176,10 @@ static void sdbRestoreTables() { totalRows += pTable->numOfRows; numOfTables++; - sdbTrace("table:%s, is restored, numOfRows:%d", pTable->tableName, pTable->numOfRows); + sdbTrace("table:%s, is restored, numOfRows:%" PRId64, pTable->tableName, pTable->numOfRows); } - sdbTrace("sdb is restored, version:%d totalRows:%d numOfTables:%d", tsSdbObj.version, totalRows, numOfTables); + sdbTrace("sdb is restored, version:%" PRId64 " totalRows:%d numOfTables:%d", tsSdbObj.version, totalRows, numOfTables); } void sdbUpdateMnodeRoles() { @@ -449,7 +451,7 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) { pthread_mutex_unlock(&pTable->mutex); - sdbTrace("table:%s, insert record:%s to hash, rowSize:%d vnumOfRows:%d version:%" PRIu64, pTable->tableName, + sdbTrace("table:%s, insert record:%s to hash, rowSize:%d vnumOfRows:%" PRId64 " version:%" PRIu64, pTable->tableName, sdbGetKeyStrFromObj(pTable, pOper->pObj), pOper->rowSize, pTable->numOfRows, sdbGetVersion()); (*pTable->insertFp)(pOper); @@ -473,7 +475,7 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) { pTable->numOfRows--; pthread_mutex_unlock(&pTable->mutex); - sdbTrace("table:%s, delete record:%s from hash, numOfRows:%d version:%" PRIu64, pTable->tableName, + sdbTrace("table:%s, delete record:%s from hash, numOfRows:%d" PRId64 "version:%" PRIu64, pTable->tableName, sdbGetKeyStrFromObj(pTable, pOper->pObj), pTable->numOfRows, sdbGetVersion()); int8_t *updateEnd = pOper->pObj + pTable->refCountPos - 1; @@ -484,7 +486,7 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) { } static int32_t sdbUpdateHash(SSdbTable *pTable, SSdbOper *pOper) { - sdbTrace("table:%s, update record:%s in hash, numOfRows:%d version:%" PRIu64, pTable->tableName, + sdbTrace("table:%s, update record:%s in hash, numOfRows:%" PRId64 " version:%" PRIu64, pTable->tableName, sdbGetKeyStrFromObj(pTable, pOper->pObj), pTable->numOfRows, sdbGetVersion()); (*pTable->updateFp)(pOper); @@ -717,7 +719,7 @@ void *sdbOpenTable(SSdbTableDesc *pDesc) { if (pTable == NULL) return NULL; - strcpy(pTable->tableName, pDesc->tableName); + tstrncpy(pTable->tableName, pDesc->tableName, SDB_TABLE_LEN); pTable->keyType = pDesc->keyType; pTable->tableId = pDesc->tableId; pTable->hashSessions = pDesc->hashSessions; diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index cb448bb564a752a33f9c0c119d47c7bcf7ecb342..deb297610dc17566ff9cb27c8b75e2c72ac69890 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -324,6 +324,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { connect_over: if (code != TSDB_CODE_SUCCESS) { + rpcFreeCont(pConnectRsp); mLError("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code)); } else { mLPrint("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code)); diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 3ce051fceea2555187bd954b3d9bcfdd6345d850..ac06cf4f3f8b4c7355904ec9da1495bb0d9beeca 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -254,7 +254,7 @@ SCacheObj *taosCacheInitWithCb(int64_t refreshTime, void (*freeCb)(void *data)) return NULL; } - pthread_attr_t thattr = {0}; + pthread_attr_t thattr; pthread_attr_init(&thattr); pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); @@ -625,4 +625,4 @@ void* taosCacheRefresh(void *handle) { } return NULL; -} \ No newline at end of file +}