From e81e999fc1542f0c78beeb4f4928cc9afe4b05d6 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Thu, 10 Oct 2024 15:40:43 +0800 Subject: [PATCH] fix: snprintf --- source/common/src/tmisce.c | 10 ++-- source/dnode/mgmt/exe/dmMain.c | 2 +- source/dnode/mgmt/mgmt_mnode/src/mmFile.c | 6 +- source/dnode/mgmt/mgmt_vnode/src/vmFile.c | 4 +- source/dnode/mgmt/node_util/src/dmFile.c | 18 +++--- source/dnode/mnode/impl/src/mndAnode.c | 4 +- source/dnode/mnode/impl/src/mndSma.c | 2 +- source/libs/stream/src/streamBackendRocksdb.c | 60 +++++++++---------- source/libs/stream/src/streamCheckpoint.c | 12 ++-- source/libs/stream/src/streamSnapshot.c | 4 +- source/libs/transport/src/thttp.c | 8 +-- source/os/src/osSysinfo.c | 10 +++- source/util/src/tanal.c | 2 +- 13 files changed, 74 insertions(+), 68 deletions(-) diff --git a/source/common/src/tmisce.c b/source/common/src/tmisce.c index 6d2b71a214..10375ba857 100644 --- a/source/common/src/tmisce.c +++ b/source/common/src/tmisce.c @@ -143,7 +143,7 @@ int32_t epsetToStr(const SEpSet* pEpSet, char* pBuf, int32_t cap) { int32_t ret = 0; int32_t nwrite = 0; - nwrite = tsnprintf(pBuf + nwrite, cap, "epset:{"); + nwrite = snprintf(pBuf + nwrite, cap, "epset:{"); if (nwrite <= 0 || nwrite >= cap) { return TSDB_CODE_OUT_OF_BUFFER; } @@ -151,9 +151,9 @@ int32_t epsetToStr(const SEpSet* pEpSet, char* pBuf, int32_t cap) { for (int _i = 0; (_i < pEpSet->numOfEps) && (cap > 0); _i++) { if (_i == pEpSet->numOfEps - 1) { - ret = tsnprintf(pBuf + nwrite, cap, "%d. %s:%d", _i, pEpSet->eps[_i].fqdn, pEpSet->eps[_i].port); + ret = snprintf(pBuf + nwrite, cap, "%d. %s:%d", _i, pEpSet->eps[_i].fqdn, pEpSet->eps[_i].port); } else { - ret = tsnprintf(pBuf + nwrite, cap, "%d. %s:%d, ", _i, pEpSet->eps[_i].fqdn, pEpSet->eps[_i].port); + ret = snprintf(pBuf + nwrite, cap, "%d. %s:%d, ", _i, pEpSet->eps[_i].fqdn, pEpSet->eps[_i].port); } if (ret <= 0 || ret >= cap) { @@ -168,7 +168,7 @@ int32_t epsetToStr(const SEpSet* pEpSet, char* pBuf, int32_t cap) { return TSDB_CODE_OUT_OF_BUFFER; } - ret = tsnprintf(pBuf + nwrite, cap, "}, inUse:%d", pEpSet->inUse); + ret = snprintf(pBuf + nwrite, cap, "}, inUse:%d", pEpSet->inUse); if (ret <= 0 || ret >= cap) { return TSDB_CODE_OUT_OF_BUFFER; } else { @@ -215,7 +215,7 @@ int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfCpu", tsNumOfCores), NULL, _exit); } - int32_t nBytes = tsnprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB); + int32_t nBytes = snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB); if (nBytes <= 9 || nBytes >= sizeof(tmp)) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_RANGE, NULL, _exit); } diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 8306406d64..ddef0537f8 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -282,7 +282,7 @@ static void dmPrintArgs(int32_t argc, char const *argv[]) { char args[1024] = {0}; int32_t arglen = tsnprintf(args, sizeof(args), "%s", argv[0]); for (int32_t i = 1; i < argc; ++i) { - arglen = arglen + snprintf(args + arglen, sizeof(args) - arglen, " %s", argv[i]); + arglen = arglen + tsnprintf(args + arglen, sizeof(args) - arglen, " %s", argv[i]); } dInfo("startup path:%s args:%s", path, args); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c index 11ed02b283..a95ec42f7e 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c @@ -64,7 +64,7 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) { SJson *pJson = NULL; char file[PATH_MAX] = {0}; - int32_t nBytes = tsnprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP); + int32_t nBytes = snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP); if (nBytes <= 0 || nBytes >= sizeof(file)) { code = TSDB_CODE_OUT_OF_BUFFER; goto _OVER; @@ -168,13 +168,13 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) { char file[PATH_MAX] = {0}; char realfile[PATH_MAX] = {0}; - int32_t nBytes = tsnprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP); + int32_t nBytes = snprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP); if (nBytes <= 0 || nBytes >= sizeof(file)) { code = TSDB_CODE_OUT_OF_BUFFER; goto _OVER; } - nBytes = tsnprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP); + nBytes = snprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP); if (nBytes <= 0 || nBytes >= sizeof(realfile)) { code = TSDB_CODE_OUT_OF_BUFFER; goto _OVER; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c index ca64ecabfc..5fabd4cdde 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c @@ -204,12 +204,12 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) { char file[PATH_MAX] = {0}; char realfile[PATH_MAX] = {0}; - int32_t nBytes = tsnprintf(file, sizeof(file), "%s%svnodes_tmp.json", pMgmt->path, TD_DIRSEP); + int32_t nBytes = snprintf(file, sizeof(file), "%s%svnodes_tmp.json", pMgmt->path, TD_DIRSEP); if (nBytes <= 0 || nBytes >= sizeof(file)) { return TSDB_CODE_OUT_OF_RANGE; } - nBytes = tsnprintf(realfile, sizeof(realfile), "%s%svnodes.json", pMgmt->path, TD_DIRSEP); + nBytes = snprintf(realfile, sizeof(realfile), "%s%svnodes.json", pMgmt->path, TD_DIRSEP); if (nBytes <= 0 || nBytes >= sizeof(realfile)) { return TSDB_CODE_OUT_OF_RANGE; } diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c index 064b107d58..1da13f72cd 100644 --- a/source/dnode/mgmt/node_util/src/dmFile.c +++ b/source/dnode/mgmt/node_util/src/dmFile.c @@ -42,7 +42,7 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) { char *content = NULL; SJson *pJson = NULL; char file[PATH_MAX] = {0}; - int32_t nBytes = tsnprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name); + int32_t nBytes = snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name); if (nBytes <= 0 || nBytes >= PATH_MAX) { code = TSDB_CODE_OUT_OF_BUFFER; goto _OVER; @@ -120,13 +120,13 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) { char file[PATH_MAX] = {0}; char realfile[PATH_MAX] = {0}; - int32_t nBytes = tsnprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name); + int32_t nBytes = snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name); if (nBytes <= 0 || nBytes >= PATH_MAX) { code = TSDB_CODE_OUT_OF_BUFFER; goto _OVER; } - nBytes = tsnprintf(realfile, sizeof(realfile), "%s%s%s.json", path, TD_DIRSEP, name); + nBytes = snprintf(realfile, sizeof(realfile), "%s%s%s.json", path, TD_DIRSEP, name); if (nBytes <= 0 || nBytes >= PATH_MAX) { code = TSDB_CODE_OUT_OF_BUFFER; goto _OVER; @@ -387,22 +387,22 @@ int32_t dmUpdateEncryptKey(char *key, bool toLogFile) { char checkFile[PATH_MAX] = {0}; char realCheckFile[PATH_MAX] = {0}; - int32_t nBytes = tsnprintf(folder, sizeof(folder), "%s%sdnode", tsDataDir, TD_DIRSEP); + int32_t nBytes = snprintf(folder, sizeof(folder), "%s%sdnode", tsDataDir, TD_DIRSEP); if (nBytes <= 0 || nBytes >= PATH_MAX) { return TSDB_CODE_OUT_OF_BUFFER; } - nBytes = tsnprintf(encryptFile, sizeof(realEncryptFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE); + nBytes = snprintf(encryptFile, sizeof(realEncryptFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE); if (nBytes <= 0 || nBytes >= PATH_MAX) { return TSDB_CODE_OUT_OF_BUFFER; } - nBytes = tsnprintf(realEncryptFile, sizeof(realEncryptFile), "%s%s%s", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE); + nBytes = snprintf(realEncryptFile, sizeof(realEncryptFile), "%s%s%s", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE); if (nBytes <= 0 || nBytes >= PATH_MAX) { return TSDB_CODE_OUT_OF_BUFFER; } - nBytes = tsnprintf(checkFile, sizeof(checkFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_CHECK_CODE_FILE); + nBytes = snprintf(checkFile, sizeof(checkFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_CHECK_CODE_FILE); if (nBytes <= 0 || nBytes >= PATH_MAX) { return TSDB_CODE_OUT_OF_BUFFER; } @@ -507,14 +507,14 @@ int32_t dmGetEncryptKey() { char *encryptKey = NULL; char *content = NULL; - int32_t nBytes = tsnprintf(encryptFile, sizeof(encryptFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, + int32_t nBytes = snprintf(encryptFile, sizeof(encryptFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_ENCRYPT_CODE_FILE); if (nBytes <= 0 || nBytes >= sizeof(encryptFile)) { code = TSDB_CODE_OUT_OF_BUFFER; return code; } - nBytes = tsnprintf(checkFile, sizeof(checkFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_CHECK_CODE_FILE); + nBytes = snprintf(checkFile, sizeof(checkFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_CHECK_CODE_FILE); if (nBytes <= 0 || nBytes >= sizeof(checkFile)) { code = TSDB_CODE_OUT_OF_BUFFER; return code; diff --git a/source/dnode/mnode/impl/src/mndAnode.c b/source/dnode/mnode/impl/src/mndAnode.c index 7e02db0e90..62c62a2abf 100644 --- a/source/dnode/mnode/impl/src/mndAnode.c +++ b/source/dnode/mnode/impl/src/mndAnode.c @@ -835,7 +835,7 @@ static int32_t mndProcessAnalAlgoReq(SRpcMsg *pReq) { for (int32_t a = 0; a < taosArrayGetSize(algos); ++a) { SAnodeAlgo *algo = taosArrayGet(algos, a); - nameLen = 1 + snprintf(name, sizeof(name) - 1, "%d:%s", url.type, algo->name); + nameLen = 1 + tsnprintf(name, sizeof(name) - 1, "%d:%s", url.type, algo->name); SAnalUrl *pOldUrl = taosHashAcquire(rsp.hash, name, nameLen); if (pOldUrl == NULL || (pOldUrl != NULL && pOldUrl->anode < url.anode)) { @@ -852,7 +852,7 @@ static int32_t mndProcessAnalAlgoReq(SRpcMsg *pReq) { goto _OVER; } - url.urlLen = 1 + snprintf(url.url, TSDB_ANAL_ANODE_URL_LEN + TSDB_ANAL_ALGO_TYPE_LEN, "%s/%s", pAnode->url, + url.urlLen = 1 + tsnprintf(url.url, TSDB_ANAL_ANODE_URL_LEN + TSDB_ANAL_ALGO_TYPE_LEN, "%s/%s", pAnode->url, taosAnalAlgoUrlStr(url.type)); if (taosHashPut(rsp.hash, name, nameLen, &url, sizeof(SAnalUrl)) != 0) { taosMemoryFree(url.url); diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index a54c7f1b14..fa2538f245 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -2252,7 +2252,7 @@ static int32_t mndRetrieveTSMA(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo if (nodeType(pFunc) == QUERY_NODE_FUNCTION) { SFunctionNode *pFuncNode = (SFunctionNode *)pFunc; if (!fmIsTSMASupportedFunc(pFuncNode->funcId)) continue; - len += tsnprintf(start, TSDB_MAX_SAVED_SQL_LEN - len, "%s%s", start != buf + VARSTR_HEADER_SIZE ? "," : "", + len += snprintf(start, TSDB_MAX_SAVED_SQL_LEN - len, "%s%s", start != buf + VARSTR_HEADER_SIZE ? "," : "", ((SExprNode *)pFunc)->userAlias); if (len >= TSDB_MAX_SAVED_SQL_LEN) { len = TSDB_MAX_SAVED_SQL_LEN; diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 5021933c33..c88971ab75 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -216,7 +216,7 @@ int32_t rebuildDirFromCheckpoint(const char* path, int64_t chkpId, char** dst) { return terrno; } - nBytes = tsnprintf(state, cap, "%s%s%s", path, TD_DIRSEP, "state"); + nBytes = snprintf(state, cap, "%s%s%s", path, TD_DIRSEP, "state"); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(state); return TSDB_CODE_OUT_OF_RANGE; @@ -229,7 +229,7 @@ int32_t rebuildDirFromCheckpoint(const char* path, int64_t chkpId, char** dst) { return terrno; } - nBytes = tsnprintf(chkp, cap, "%s%s%s%scheckpoint%" PRId64 "", path, TD_DIRSEP, "checkpoints", TD_DIRSEP, chkpId); + nBytes = snprintf(chkp, cap, "%s%s%s%scheckpoint%" PRId64 "", path, TD_DIRSEP, "checkpoints", TD_DIRSEP, chkpId); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(state); taosMemoryFree(chkp); @@ -282,7 +282,7 @@ int32_t remoteChkp_readMetaData(char* path, SSChkpMetaOnS3** pMeta) { return terrno; } - int32_t n = tsnprintf(metaPath, cap, "%s%s%s", path, TD_DIRSEP, "META"); + int32_t n = snprintf(metaPath, cap, "%s%s%s", path, TD_DIRSEP, "META"); if (n <= 0 || n >= cap) { taosMemoryFree(metaPath); return TSDB_CODE_OUT_OF_MEMORY; @@ -350,7 +350,7 @@ int32_t remoteChkp_validAndCvtMeta(char* path, SSChkpMetaOnS3* pMeta, int64_t ch goto _EXIT; } - nBytes = tsnprintf(src, cap, "%s%s%s_%" PRId64 "", path, TD_DIRSEP, key, pMeta->currChkptId); + nBytes = snprintf(src, cap, "%s%s%s_%" PRId64 "", path, TD_DIRSEP, key, pMeta->currChkptId); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _EXIT; @@ -361,7 +361,7 @@ int32_t remoteChkp_validAndCvtMeta(char* path, SSChkpMetaOnS3* pMeta, int64_t ch goto _EXIT; } - nBytes = tsnprintf(dst, cap, "%s%s%s", path, TD_DIRSEP, key); + nBytes = snprintf(dst, cap, "%s%s%s", path, TD_DIRSEP, key); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _EXIT; @@ -403,7 +403,7 @@ int32_t remoteChkpGetDelFile(char* path, SArray* toDel) { return terrno; } - nBytes = tsnprintf(p, cap, "%s_%" PRId64 "", key, pMeta->currChkptId); + nBytes = snprintf(p, cap, "%s_%" PRId64 "", key, pMeta->currChkptId); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(pMeta); taosMemoryFree(p); @@ -499,7 +499,7 @@ int32_t rebuildFromRemoteChkp_s3(const char* key, char* chkpPath, int64_t chkpId return terrno; } - int32_t nBytes = tsnprintf(defaultPath, cap, "%s%s", defaultPath, "_tmp"); + int32_t nBytes = snprintf(defaultPath, cap, "%s%s", defaultPath, "_tmp"); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(defaultPath); return TSDB_CODE_OUT_OF_RANGE; @@ -611,13 +611,13 @@ int32_t backendFileCopyFilesImpl(const char* src, const char* dst) { continue; } - nBytes = tsnprintf(srcName, cap, "%s%s%s", src, TD_DIRSEP, name); + nBytes = snprintf(srcName, cap, "%s%s%s", src, TD_DIRSEP, name); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _ERROR; } - nBytes = tsnprintf(dstName, cap, "%s%s%s", dst, TD_DIRSEP, name); + nBytes = snprintf(dstName, cap, "%s%s%s", dst, TD_DIRSEP, name); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _ERROR; @@ -715,7 +715,7 @@ int32_t restoreCheckpointData(const char* path, const char* key, int64_t chkptId goto _EXIT; } - nBytes = tsnprintf(prefixPath, cap, "%s%s%s", path, TD_DIRSEP, key); + nBytes = snprintf(prefixPath, cap, "%s%s%s", path, TD_DIRSEP, key); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _EXIT; @@ -727,7 +727,7 @@ int32_t restoreCheckpointData(const char* path, const char* key, int64_t chkptId goto _EXIT; } - nBytes = tsnprintf(defaultPath, cap, "%s%s%s", prefixPath, TD_DIRSEP, "state"); + nBytes = snprintf(defaultPath, cap, "%s%s%s", prefixPath, TD_DIRSEP, "state"); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _EXIT; @@ -739,7 +739,7 @@ int32_t restoreCheckpointData(const char* path, const char* key, int64_t chkptId goto _EXIT; } - nBytes = tsnprintf(checkpointRoot, cap, "%s%s%s", prefixPath, TD_DIRSEP, "checkpoints"); + nBytes = snprintf(checkpointRoot, cap, "%s%s%s", prefixPath, TD_DIRSEP, "checkpoints"); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _EXIT; @@ -753,7 +753,7 @@ int32_t restoreCheckpointData(const char* path, const char* key, int64_t chkptId stDebug("%s check local backend dir:%s, checkpointId:%" PRId64 " succ", key, defaultPath, chkptId); if (chkptId > 0) { - nBytes = tsnprintf(checkpointPath, cap, "%s%s%s%s%s%" PRId64 "", prefixPath, TD_DIRSEP, "checkpoints", TD_DIRSEP, + nBytes = snprintf(checkpointPath, cap, "%s%s%s%s%s%" PRId64 "", prefixPath, TD_DIRSEP, "checkpoints", TD_DIRSEP, "checkpoint", chkptId); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; @@ -800,7 +800,7 @@ bool streamBackendDataIsExist(const char* path, int64_t chkpId) { return false; } - int16_t nBytes = tsnprintf(state, cap, "%s%s%s", path, TD_DIRSEP, "state"); + int16_t nBytes = snprintf(state, cap, "%s%s%s", path, TD_DIRSEP, "state"); if (nBytes <= 0 || nBytes >= cap) { terrno = TSDB_CODE_OUT_OF_RANGE; exist = false; @@ -1322,13 +1322,13 @@ int32_t chkpPreBuildDir(char* path, int64_t chkpId, char** chkpDir, char** chkpI goto _EXIT; } - nBytes = tsnprintf(pChkpDir, cap, "%s%s%s", path, TD_DIRSEP, "checkpoints"); + nBytes = snprintf(pChkpDir, cap, "%s%s%s", path, TD_DIRSEP, "checkpoints"); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _EXIT; } - nBytes = tsnprintf(pChkpIdDir, cap, "%s%s%s%" PRId64, pChkpDir, TD_DIRSEP, "checkpoint", chkpId); + nBytes = snprintf(pChkpIdDir, cap, "%s%s%s%" PRId64, pChkpDir, TD_DIRSEP, "checkpoint", chkpId); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _EXIT; @@ -1500,7 +1500,7 @@ int32_t chkpLoadExtraInfo(char* pChkpIdDir, int64_t* chkpId, int64_t* processId) goto _EXIT; } - nBytes = tsnprintf(pDst, cap, "%s%sinfo", pChkpIdDir, TD_DIRSEP); + nBytes = snprintf(pDst, cap, "%s%sinfo", pChkpIdDir, TD_DIRSEP); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; stError("failed to build dst to load extra info, dir:%s", pChkpIdDir); @@ -1556,7 +1556,7 @@ int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) { goto _EXIT; } - nBytes = tsnprintf(pDst, cap, "%s%sinfo", pChkpIdDir, TD_DIRSEP); + nBytes = snprintf(pDst, cap, "%s%sinfo", pChkpIdDir, TD_DIRSEP); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; stError("failed to build dst to add extra info, dir:%s, reason:%s", pChkpIdDir, tstrerror(code)); @@ -1570,7 +1570,7 @@ int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) { goto _EXIT; } - nBytes = tsnprintf(buf, sizeof(buf), "%" PRId64 " %" PRId64 "", chkpId, processId); + nBytes = snprintf(buf, sizeof(buf), "%" PRId64 " %" PRId64 "", chkpId, processId); if (nBytes <= 0 || nBytes >= sizeof(buf)) { code = TSDB_CODE_OUT_OF_RANGE; stError("failed to build content to add extra info, dir:%s,reason:%s", pChkpIdDir, tstrerror(code)); @@ -2727,7 +2727,7 @@ int32_t taskDbGenChkpUploadData__s3(STaskDbWrapper* pDb, void* bkdChkpMgt, int64 return terrno; } - int32_t nBytes = tsnprintf(temp, cap, "%s%s%s%" PRId64, pDb->path, TD_DIRSEP, "tmp", chkpId); + int32_t nBytes = snprintf(temp, cap, "%s%s%s%" PRId64, pDb->path, TD_DIRSEP, "tmp", chkpId); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(temp); return TSDB_CODE_OUT_OF_RANGE; @@ -4805,14 +4805,14 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { char* srcDir = &dstBuf[cap]; char* dstDir = &srcDir[cap]; - int nBytes = tsnprintf(srcDir, cap, "%s%s%s%s%s%" PRId64 "", p->path, TD_DIRSEP, "checkpoints", TD_DIRSEP, + int nBytes = snprintf(srcDir, cap, "%s%s%s%s%s%" PRId64 "", p->path, TD_DIRSEP, "checkpoints", TD_DIRSEP, "checkpoint", p->curChkpId); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _ERROR; } - nBytes = tsnprintf(dstDir, cap, "%s", dname); + nBytes = snprintf(dstDir, cap, "%s", dname); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _ERROR; @@ -4837,13 +4837,13 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { memset(dstBuf, 0, cap); char* filename = taosArrayGetP(p->pAdd, i); - nBytes = tsnprintf(srcBuf, cap, "%s%s%s", srcDir, TD_DIRSEP, filename); + nBytes = snprintf(srcBuf, cap, "%s%s%s", srcDir, TD_DIRSEP, filename); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _ERROR; } - nBytes = tsnprintf(dstBuf, cap, "%s%s%s", dstDir, TD_DIRSEP, filename); + nBytes = snprintf(dstBuf, cap, "%s%s%s", dstDir, TD_DIRSEP, filename); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _ERROR; @@ -4874,13 +4874,13 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { memset(srcBuf, 0, cap); memset(dstBuf, 0, cap); - nBytes = tsnprintf(srcBuf, cap, "%s%s%s", srcDir, TD_DIRSEP, p->pCurrent); + nBytes = snprintf(srcBuf, cap, "%s%s%s", srcDir, TD_DIRSEP, p->pCurrent); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _ERROR; } - nBytes = tsnprintf(dstBuf, cap, "%s%s%s_%" PRId64 "", dstDir, TD_DIRSEP, p->pCurrent, p->curChkpId); + nBytes = snprintf(dstBuf, cap, "%s%s%s_%" PRId64 "", dstDir, TD_DIRSEP, p->pCurrent, p->curChkpId); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _ERROR; @@ -4896,13 +4896,13 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { memset(srcBuf, 0, cap); memset(dstBuf, 0, cap); - nBytes = tsnprintf(srcBuf, cap, "%s%s%s", srcDir, TD_DIRSEP, p->pManifest); + nBytes = snprintf(srcBuf, cap, "%s%s%s", srcDir, TD_DIRSEP, p->pManifest); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _ERROR; } - nBytes = tsnprintf(dstBuf, cap, "%s%s%s_%" PRId64 "", dstDir, TD_DIRSEP, p->pManifest, p->curChkpId); + nBytes = snprintf(dstBuf, cap, "%s%s%s_%" PRId64 "", dstDir, TD_DIRSEP, p->pManifest, p->curChkpId); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _ERROR; @@ -4914,7 +4914,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { goto _ERROR; } memset(dstBuf, 0, cap); - nBytes = tsnprintf(dstDir, cap, "%s%s%s", dstDir, TD_DIRSEP, chkpMeta); + nBytes = snprintf(dstDir, cap, "%s%s%s", dstDir, TD_DIRSEP, chkpMeta); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; goto _ERROR; @@ -5018,7 +5018,7 @@ int32_t bkdMgtGetDelta(SBkdMgt* bm, char* taskId, int64_t chkpId, SArray* list, return terrno; } - int32_t nBytes = tsnprintf(path, cap, "%s%s%s", bm->path, TD_DIRSEP, taskId); + int32_t nBytes = snprintf(path, cap, "%s%s%s", bm->path, TD_DIRSEP, taskId); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(path); TAOS_UNUSED(taosThreadRwlockUnlock(&bm->rwLock)); diff --git a/source/libs/stream/src/streamCheckpoint.c b/source/libs/stream/src/streamCheckpoint.c index 91c7d9e2ac..e44bca123b 100644 --- a/source/libs/stream/src/streamCheckpoint.c +++ b/source/libs/stream/src/streamCheckpoint.c @@ -710,7 +710,7 @@ static int32_t getCheckpointDataMeta(const char* id, const char* path, SArray* l return terrno; } - int32_t nBytes = tsnprintf(filePath, cap, "%s%s%s", path, TD_DIRSEP, "META_TMP"); + int32_t nBytes = snprintf(filePath, cap, "%s%s%s", path, TD_DIRSEP, "META_TMP"); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(filePath); return TSDB_CODE_OUT_OF_RANGE; @@ -1304,13 +1304,13 @@ static int32_t uploadCheckpointToS3(const char* id, const char* path) { char filename[PATH_MAX] = {0}; if (path[strlen(path) - 1] == TD_DIRSEP_CHAR) { - nBytes = tsnprintf(filename, sizeof(filename), "%s%s", path, name); + nBytes = snprintf(filename, sizeof(filename), "%s%s", path, name); if (nBytes <= 0 || nBytes >= sizeof(filename)) { code = TSDB_CODE_OUT_OF_RANGE; break; } } else { - nBytes = tsnprintf(filename, sizeof(filename), "%s%s%s", path, TD_DIRSEP, name); + nBytes = snprintf(filename, sizeof(filename), "%s%s%s", path, TD_DIRSEP, name); if (nBytes <= 0 || nBytes >= sizeof(filename)) { code = TSDB_CODE_OUT_OF_RANGE; break; @@ -1318,7 +1318,7 @@ static int32_t uploadCheckpointToS3(const char* id, const char* path) { } char object[PATH_MAX] = {0}; - nBytes = tsnprintf(object, sizeof(object), "%s%s%s", id, TD_DIRSEP, name); + nBytes = snprintf(object, sizeof(object), "%s%s%s", id, TD_DIRSEP, name); if (nBytes <= 0 || nBytes >= sizeof(object)) { code = TSDB_CODE_OUT_OF_RANGE; break; @@ -1349,7 +1349,7 @@ int32_t downloadCheckpointByNameS3(const char* id, const char* fname, const char return terrno; } - nBytes = tsnprintf(buf, cap, "%s/%s", id, fname); + nBytes = snprintf(buf, cap, "%s/%s", id, fname); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(buf); return TSDB_CODE_OUT_OF_RANGE; @@ -1439,7 +1439,7 @@ int32_t deleteCheckpoint(const char* id) { int32_t deleteCheckpointFile(const char* id, const char* name) { char object[128] = {0}; - int32_t nBytes = tsnprintf(object, sizeof(object), "%s/%s", id, name); + int32_t nBytes = snprintf(object, sizeof(object), "%s/%s", id, name); if (nBytes <= 0 || nBytes >= sizeof(object)) { return TSDB_CODE_OUT_OF_RANGE; } diff --git a/source/libs/stream/src/streamSnapshot.c b/source/libs/stream/src/streamSnapshot.c index 951ca43732..ae8a71d988 100644 --- a/source/libs/stream/src/streamSnapshot.c +++ b/source/libs/stream/src/streamSnapshot.c @@ -164,7 +164,7 @@ void snapFileDebugInfo(SBackendSnapFile2* pSnapFile) { return; } - int32_t nBytes = tsnprintf(buf + strlen(buf), cap, "["); + int32_t nBytes = snprintf(buf + strlen(buf), cap, "["); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(buf); stError("%s failed to write buf, reason:%s", STREAM_STATE_TRANSFER, tstrerror(TSDB_CODE_OUT_OF_RANGE)); @@ -355,7 +355,7 @@ int32_t streamBackendSnapInitFile(char* metaPath, SStreamTaskSnap* pSnap, SBacke return terrno; } - nBytes = tsnprintf(path, cap, "%s%s%s%s%s%" PRId64 "", pSnap->dbPrefixPath, TD_DIRSEP, "checkpoints", TD_DIRSEP, + nBytes = snprintf(path, cap, "%s%s%s%s%s%" PRId64 "", pSnap->dbPrefixPath, TD_DIRSEP, "checkpoints", TD_DIRSEP, "checkpoint", pSnap->chkpId); if (nBytes <= 0 || nBytes >= cap) { code = TSDB_CODE_OUT_OF_RANGE; diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index ead985ff99..7d7868f3cd 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -102,14 +102,14 @@ static int32_t taosBuildHttpHeader(const char* server, const char* uri, int32_t int32_t len = 0; if (flag == HTTP_FLAT) { if (qid == NULL) { - len = tsnprintf(pHead, headLen, + len = snprintf(pHead, headLen, "POST %s HTTP/1.1\n" "Host: %s\n" "Content-Type: application/json\n" "Content-Length: %d\n\n", uri, server, contLen); } else { - len = tsnprintf(pHead, headLen, + len = snprintf(pHead, headLen, "POST %s HTTP/1.1\n" "Host: %s\n" "X-QID: %s\n" @@ -122,7 +122,7 @@ static int32_t taosBuildHttpHeader(const char* server, const char* uri, int32_t } } else if (flag == HTTP_GZIP) { if (qid == NULL) { - len = tsnprintf(pHead, headLen, + len = snprintf(pHead, headLen, "POST %s HTTP/1.1\n" "Host: %s\n" "Content-Type: application/json\n" @@ -130,7 +130,7 @@ static int32_t taosBuildHttpHeader(const char* server, const char* uri, int32_t "Content-Length: %d\n\n", uri, server, contLen); } else { - len = tsnprintf(pHead, headLen, + len = snprintf(pHead, headLen, "POST %s HTTP/1.1\n" "Host: %s\n" "X-QID: %s\n" diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 631cf6fca0..6d4629f476 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -1042,9 +1042,12 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { if (h != S_OK) { return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } - snprintf(uid, uidlen, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3, + int n = snprintf(uid, uidlen, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); + if(n >= uidlen) { + return TSDB_CODE_OUT_OF_BUFFER;; + } return 0; #elif defined(_TD_DARWIN_64) @@ -1054,7 +1057,10 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { uuid_generate(uuid); // it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null uuid_unparse_lower(uuid, buf); - int n = tsnprintf(uid, uidlen, "%.*s", (int)sizeof(buf), buf); // though less performance, much safer + int n = snprintf(uid, uidlen, "%.*s", (int)sizeof(buf), buf); // though less performance, much safer + if(n >= uidlen) { + return TSDB_CODE_OUT_OF_BUFFER;; + } return 0; #else int64_t len = 0; diff --git a/source/util/src/tanal.c b/source/util/src/tanal.c index aa9fe9a174..a00a2dd2eb 100644 --- a/source/util/src/tanal.c +++ b/source/util/src/tanal.c @@ -156,7 +156,7 @@ bool taosAnalGetOptInt(const char *option, const char *optName, int32_t *optValu int32_t taosAnalGetAlgoUrl(const char *algoName, EAnalAlgoType type, char *url, int32_t urlLen) { int32_t code = 0; char name[TSDB_ANAL_ALGO_KEY_LEN] = {0}; - int32_t nameLen = 1 + snprintf(name, sizeof(name) - 1, "%d:%s", type, algoName); + int32_t nameLen = 1 + tsnprintf(name, sizeof(name) - 1, "%d:%s", type, algoName); taosThreadMutexLock(&tsAlgos.lock); SAnalUrl *pUrl = taosHashAcquire(tsAlgos.hash, name, nameLen);