Merge pull request #29079 from taosdata/fix/TD-32405
enh(meta): use memory safe functions
This commit is contained in:
commit
3fc511c128
|
@ -138,6 +138,7 @@ static int32_t metaOpenImpl(SVnode *pVnode, SMeta **ppMeta, const char *metaDir,
|
|||
int32_t code = 0;
|
||||
int32_t lino;
|
||||
int32_t offset;
|
||||
int32_t pathLen = 0;
|
||||
char path[TSDB_FILENAME_LEN] = {0};
|
||||
char indexFullPath[128] = {0};
|
||||
|
||||
|
@ -150,14 +151,15 @@ static int32_t metaOpenImpl(SVnode *pVnode, SMeta **ppMeta, const char *metaDir,
|
|||
taosRemoveDir(path);
|
||||
}
|
||||
|
||||
if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + strlen(path) + 1)) == NULL) {
|
||||
pathLen = strlen(path) + 1;
|
||||
if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + pathLen)) == NULL) {
|
||||
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||
}
|
||||
|
||||
metaInitLock(pMeta);
|
||||
|
||||
pMeta->path = (char *)&pMeta[1];
|
||||
strcpy(pMeta->path, path);
|
||||
tstrncpy(pMeta->path, path, pathLen);
|
||||
int32_t ret = taosRealPath(pMeta->path, NULL, strlen(path) + 1);
|
||||
|
||||
pMeta->pVnode = pVnode;
|
||||
|
|
|
@ -1189,7 +1189,7 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs
|
|||
(*pMetaRsp)->tableType = TSDB_CHILD_TABLE;
|
||||
(*pMetaRsp)->tuid = pReq->uid;
|
||||
(*pMetaRsp)->suid = pReq->ctb.suid;
|
||||
strcpy((*pMetaRsp)->tbName, pReq->name);
|
||||
tstrncpy((*pMetaRsp)->tbName, pReq->name, strlen(pReq->name) + 1);
|
||||
} else {
|
||||
ret = metaUpdateMetaRsp(pReq->uid, pReq->name, &pReq->ntb.schemaRow, *pMetaRsp);
|
||||
if (ret < 0) {
|
||||
|
@ -1834,7 +1834,8 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].type = pAlterTbReq->type;
|
||||
pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].flags = pAlterTbReq->flags;
|
||||
pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].colId = entry.ntbEntry.ncid++;
|
||||
strcpy(pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].name, pAlterTbReq->colName);
|
||||
tstrncpy(pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].name, pAlterTbReq->colName,
|
||||
strlen(pAlterTbReq->colName) + 1);
|
||||
|
||||
++pMeta->pVnode->config.vndStats.numOfNTimeSeries;
|
||||
metaTimeSeriesNotifyCheck(pMeta);
|
||||
|
@ -1943,7 +1944,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
goto _err;
|
||||
}
|
||||
pSchema->version++;
|
||||
strcpy(pColumn->name, pAlterTbReq->colNewName);
|
||||
tstrncpy(pColumn->name, pAlterTbReq->colNewName, strlen(pAlterTbReq->colNewName) + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,18 +49,20 @@ const char *ttlV1Tbname = "ttlv1.idx";
|
|||
int32_t ttlMgrOpen(STtlManger **ppTtlMgr, TDB *pEnv, int8_t rollback, const char *logPrefix, int32_t flushThreshold) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int64_t startNs = taosGetTimestampNs();
|
||||
int32_t pathLen = 0;
|
||||
|
||||
*ppTtlMgr = NULL;
|
||||
|
||||
STtlManger *pTtlMgr = (STtlManger *)tdbOsCalloc(1, sizeof(*pTtlMgr));
|
||||
if (pTtlMgr == NULL) TAOS_RETURN(terrno);
|
||||
|
||||
char *logBuffer = (char *)tdbOsCalloc(1, strlen(logPrefix) + 1);
|
||||
pathLen = strlen(logPrefix) + 1;
|
||||
char *logBuffer = (char *)tdbOsCalloc(1, pathLen);
|
||||
if (logBuffer == NULL) {
|
||||
tdbOsFree(pTtlMgr);
|
||||
TAOS_RETURN(terrno);
|
||||
}
|
||||
(void)strcpy(logBuffer, logPrefix);
|
||||
tstrncpy(logBuffer, logPrefix, pathLen);
|
||||
pTtlMgr->logPrefix = logBuffer;
|
||||
pTtlMgr->flushThreshold = flushThreshold;
|
||||
|
||||
|
|
Loading…
Reference in New Issue