diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index ab2d7d7830ff02bf3ba9f0b840f5ef842a1c455f..372e81d7371debe904ac7ad1e6a9caecb54ccb28 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5420,7 +5420,7 @@ int32_t doLocalQueryProcess(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) { tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize, false); const char* name = (pExprList->a[0].aliasName != NULL)? pExprList->a[0].aliasName:functionsInfo[index].name; - strncpy(pExpr1->aliasName, name, tListLen(pExpr1->aliasName)); + tstrncpy(pExpr1->aliasName, name, tListLen(pExpr1->aliasName)); return TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 8815e463ad9742c0aacd1d38f1de6e5ca56617eb..33ab93d113a565cb7526c5a5eb016ab5dda432e4 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1018,7 +1018,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCMDropDnodeMsg *pDrop = (SCMDropDnodeMsg *)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); - strcpy(pDrop->ep, pTableMetaInfo->name); + tstrncpy(pDrop->ep, pTableMetaInfo->name, sizeof(pDrop->ep)); pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_DNODE; return TSDB_CODE_SUCCESS; @@ -1036,7 +1036,7 @@ int32_t tscBuildDropUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); - strcpy(pDropMsg->user, pTableMetaInfo->name); + tstrncpy(pDropMsg->user, pTableMetaInfo->name, sizeof(pDropMsg->user)); return TSDB_CODE_SUCCESS; } @@ -1091,9 +1091,9 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); size_t nameLen = strlen(pTableMetaInfo->name); if (nameLen > 0) { - strcpy(pShowMsg->db, pTableMetaInfo->name); // prefix is set here + tstrncpy(pShowMsg->db, pTableMetaInfo->name, sizeof(pShowMsg->db)); // prefix is set here } else { - strcpy(pShowMsg->db, pObj->db); + tstrncpy(pShowMsg->db, pObj->db, sizeof(pShowMsg->db)); } SShowInfo *pShowInfo = &pInfo->pDCLInfo->showOpt; @@ -1300,7 +1300,7 @@ int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCMAlterDbMsg *pAlterDbMsg = (SCMAlterDbMsg*)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); - strcpy(pAlterDbMsg->db, pTableMetaInfo->name); + tstrncpy(pAlterDbMsg->db, pTableMetaInfo->name, sizeof(pAlterDbMsg->db)); return TSDB_CODE_SUCCESS; } @@ -2150,7 +2150,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) { SSqlRes *pRes = &pSql->res; SCMConnectRsp *pConnect = (SCMConnectRsp *)pRes->pRsp; - strcpy(pObj->acctId, pConnect->acctId); // copy acctId from response + tstrncpy(pObj->acctId, pConnect->acctId, sizeof(pObj->acctId)); // copy acctId from response int32_t len = sprintf(temp, "%s%s%s", pObj->acctId, TS_PATH_DELIMITER, pObj->db); assert(len <= sizeof(pObj->db)); @@ -2172,7 +2172,7 @@ int tscProcessUseDbRsp(SSqlObj *pSql) { STscObj * pObj = pSql->pTscObj; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0); - strcpy(pObj->db, pTableMetaInfo->name); + tstrncpy(pObj->db, pTableMetaInfo->name, sizeof(pObj->db)); return 0; } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index a810e5d4be748ef07a7de52fc6b2b018e13eb317..2701d2b572d9f893b265c6cc1262ee08d4bbaf6f 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -593,7 +593,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff dataBuf->size = startOffset; dataBuf->tsSource = -1; - strncpy(dataBuf->tableId, name, TSDB_TABLE_ID_LEN); + tstrncpy(dataBuf->tableId, name, sizeof(dataBuf->tableId)); /* * The table meta may be released since the table meta cache are completed clean by other thread @@ -1666,7 +1666,7 @@ STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST assert(pTableMetaInfo != NULL); if (name != NULL) { - strncpy(pTableMetaInfo->name, name, TSDB_TABLE_ID_LEN); + tstrncpy(pTableMetaInfo->name, name, sizeof(pTableMetaInfo->name)); } pTableMetaInfo->pTableMeta = pTableMeta; diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index edb588b5544531d538529e3e027cf3dedeb44a0d..13f3c0a2b0a0a75e07329a24f13ab0b9a274d3ac 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -73,8 +73,8 @@ void *cqOpen(void *ahandle, const SCqCfg *pCfg) { return NULL; } - strcpy(pContext->user, pCfg->user); - strcpy(pContext->pass, pCfg->pass); + tstrncpy(pContext->user, pCfg->user, sizeof(pContext->user)); + tstrncpy(pContext->pass, pCfg->pass, sizeof(pContext->pass)); const char* db = pCfg->db; for (const char* p = db; *p != 0; p++) { if (*p == '.') { @@ -82,7 +82,7 @@ void *cqOpen(void *ahandle, const SCqCfg *pCfg) { break; } } - strcpy(pContext->db, db); + tstrncpy(pContext->db, db, sizeof(pContext->db)); pContext->vgId = pCfg->vgId; pContext->cqWrite = pCfg->cqWrite; pContext->ahandle = ahandle; @@ -215,7 +215,7 @@ void cqDrop(void *handle) { cTrace("vgId:%d, id:%d CQ:%s is dropped", pContext->vgId, pObj->tid, pObj->sqlStr); free(pObj); - pthread_mutex_lock(&pContext->mutex); + pthread_mutex_unlock(&pContext->mutex); } static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index dca8287394f3a6e401c0527daa238875fb88f693..6a0219d6fc3218218d6d9cd9db0bfd82f13c8d21 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -296,7 +296,7 @@ typedef struct { } SCMConnectMsg; typedef struct { - char acctId[TSDB_ACCT_LEN + 1]; + char acctId[TSDB_ACCT_LEN]; char serverVersion[TSDB_VERSION_LEN]; int8_t writeAuth; int8_t superAuth; diff --git a/src/inc/tcq.h b/src/inc/tcq.h index 9d987da468eaa83a0324d106fa19563c95608e6d..32b75674c3278b3273fd4b98dd645f4168543155 100644 --- a/src/inc/tcq.h +++ b/src/inc/tcq.h @@ -27,7 +27,7 @@ typedef struct { int vgId; char user[TSDB_USER_LEN]; char pass[TSDB_PASSWORD_LEN]; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; FCqWrite cqWrite; } SCqCfg; diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index ca0af9614524109787e7ac30f9a91d366ac2b164..8fb894a588ba6926cc07a6a2444f6d334d883770 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -756,7 +756,7 @@ void *readMetric(void *sarg) { for (int j = 0; j < n; j++) { char condition[BUFFER_SIZE - 30] = "\0"; - char tempS[BUFFER_SIZE] = "\0"; + char tempS[64] = "\0"; int m = 10 < num_of_tables ? 10 : num_of_tables; diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 417de629aa5d1724d18fc3fb393d4b0b300a9b57..6cb57ef0d5f5d33df97ce8f1666bce430f7ef016 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -643,6 +643,8 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) { lseek(fd, 0, SEEK_SET); while (read(fd, &tableRecord, sizeof(STableRecord)) > 0) { + tableRecord.name[sizeof(tableRecord.name) - 1] = 0; + tableRecord.metric[sizeof(tableRecord.metric) - 1] = 0; taosDumpTable(tableRecord.name, tableRecord.metric, arguments, fp); } @@ -902,6 +904,8 @@ int32_t taosDumpMetric(char *metric, SDumpArguments *arguments, FILE *fp) { lseek(fd, 0, SEEK_SET); while (read(fd, &tableRecord, sizeof(STableRecord)) > 0) { + tableRecord.name[sizeof(tableRecord.name) - 1] = 0; + tableRecord.metric[sizeof(tableRecord.metric) - 1] = 0; taosDumpTable(tableRecord.name, tableRecord.metric, arguments, fp); } diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index 35ae9aad33ade1edbc5e37caf952b74cb5413fa5..14cd4057632b1abc834a5393e4a6424dc2d1ef8d 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -32,8 +32,8 @@ struct SMnodeObj; typedef struct SDnodeObj { int32_t dnodeId; uint16_t dnodePort; - char dnodeFqdn[TSDB_FQDN_LEN + 1]; - char dnodeEp[TSDB_EP_LEN + 1]; + char dnodeFqdn[TSDB_FQDN_LEN]; + char dnodeEp[TSDB_EP_LEN]; int64_t createdTime; uint32_t lastAccess; int32_t openVnodes; diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index cde94c39b5d230eaa69cb84a57504d9e1e5022ce..a2ddd9893f50495d3235d5feb8cc513638569209 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -1769,8 +1769,8 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) { return TSDB_CODE_MND_OUT_OF_MEMORY; } - strncpy(pCreateMsg->tableId, pInfo->tableId, tListLen(pInfo->tableId)); - strcpy(pCreateMsg->db, pMsg->pDb->name); + tstrncpy(pCreateMsg->tableId, pInfo->tableId, sizeof(pInfo->tableId)); + tstrncpy(pCreateMsg->db, pMsg->pDb->name, sizeof(pCreateMsg->db)); pCreateMsg->igExists = 1; pCreateMsg->getMeta = 1; pCreateMsg->contLen = htonl(contLen); diff --git a/src/os/linux/src/linuxSysPara.c b/src/os/linux/src/linuxSysPara.c index 3ec7de3b635253d6936be9137c4c3ee6ff8b4d15..8ae2630a1547b3716cc89433ec4f539c3a89e12d 100644 --- a/src/os/linux/src/linuxSysPara.c +++ b/src/os/linux/src/linuxSysPara.c @@ -160,7 +160,7 @@ static void taosGetSystemTimezone() { /* load time zone string from /etc/timezone */ FILE *f = fopen("/etc/timezone", "r"); - char buf[64] = {0}; + char buf[65] = {0}; if (f != NULL) { fread(buf, 64, 1, f); fclose(f); diff --git a/src/plugins/http/src/httpAuth.c b/src/plugins/http/src/httpAuth.c index 594f51e275a6db6ecd21307c0e24808656ed779b..ccf39642c9472a3ec971ecc2e763f7fa9d5fd72d 100644 --- a/src/plugins/http/src/httpAuth.c +++ b/src/plugins/http/src/httpAuth.c @@ -88,8 +88,8 @@ bool httpParseTaosdAuthToken(HttpContext *pContext, char *token, int len) { free(base64); return false; } else { - strncpy(pContext->user, descrypt, TSDB_USER_LEN); - strncpy(pContext->pass, descrypt + TSDB_USER_LEN, TSDB_PASSWORD_LEN); + tstrncpy(pContext->user, descrypt, sizeof(pContext->user)); + tstrncpy(pContext->pass, descrypt + TSDB_USER_LEN, TSDB_PASSWORD_LEN); httpTrace("context:%p, fd:%d, ip:%s, taosd token:%s parsed success, user:%s", pContext, pContext->fd, pContext->ipstr, token, pContext->user); diff --git a/src/plugins/monitor/src/monitorMain.c b/src/plugins/monitor/src/monitorMain.c index 01e276da64936cf85d30b1cc385ed6c5646bd625..ff9faa845c104d165db097595f4f7133eb313fc9 100644 --- a/src/plugins/monitor/src/monitorMain.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -156,7 +156,7 @@ static void dnodeBuildMonitorSql(char *sql, int32_t cmd) { ", io_read float, io_write float" ", req_http int, req_select int, req_insert int" ") tags (dnodeid int, fqdn binary(%d))", - tsMonitorDbName, TSDB_FQDN_LEN + 1); + tsMonitorDbName, TSDB_FQDN_LEN); } else if (cmd == MONITOR_CMD_CREATE_TB_DN) { snprintf(sql, SQL_LENGTH, "create table if not exists %s.dn%d using %s.dn tags(%d, '%s')", tsMonitorDbName, dnodeGetDnodeId(), tsMonitorDbName, dnodeGetDnodeId(), tsLocalEp); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 92c23f6b8377a34876f15bd7bf9de40878c2d933..65a5ef45d37ed36a7dcc006d8b5ddeed744beae1 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -5242,7 +5242,7 @@ static int32_t createFilterInfo(void *pQInfo, SQuery *pQuery) { if (pQuery->colList[i].numOfFilters > 0) { SSingleColumnFilterInfo *pFilterInfo = &pQuery->pFilterInfo[j]; - memcpy(&pFilterInfo->info, &pQuery->colList[i], sizeof(SColumnInfoData)); + memcpy(&pFilterInfo->info, &pQuery->colList[i], sizeof(SColumnInfo)); pFilterInfo->info = pQuery->colList[i]; pFilterInfo->numOfFilters = pQuery->colList[i].numOfFilters; diff --git a/tests/tsim/src/simMain.c b/tests/tsim/src/simMain.c index 2540851634f41706d4255b6757e87442d2d3d3d5..f016e36d4134a48baf80023b835d9973fdcc0ac4 100644 --- a/tests/tsim/src/simMain.c +++ b/tests/tsim/src/simMain.c @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) { for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "-c") == 0 && i < argc - 1) { - strncpy(configDir, argv[++i], MAX_FILE_NAME_LEN); + tstrncpy(configDir, argv[++i], MAX_FILE_NAME_LEN); } else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) { strcpy(scriptFile, argv[++i]); } else if (strcmp(argv[i], "-a") == 0) {