This commit is contained in:
yihaoDeng 2024-12-09 14:35:12 +08:00
parent b5642faef5
commit 32b5ec1da7
10 changed files with 17 additions and 16 deletions

View File

@ -186,7 +186,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
#if defined(TD_ENTERPRISE) #if defined(TD_ENTERPRISE)
pCfg->tsdbCfg.encryptAlgorithm = pCreate->encryptAlgorithm; pCfg->tsdbCfg.encryptAlgorithm = pCreate->encryptAlgorithm;
if (pCfg->tsdbCfg.encryptAlgorithm == DND_CA_SM4) { if (pCfg->tsdbCfg.encryptAlgorithm == DND_CA_SM4) {
tstrncpy(pCfg->tsdbCfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); tstrncpy(pCfg->tsdbCfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN + 1);
} }
#else #else
pCfg->tsdbCfg.encryptAlgorithm = 0; pCfg->tsdbCfg.encryptAlgorithm = 0;
@ -202,7 +202,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
#if defined(TD_ENTERPRISE) #if defined(TD_ENTERPRISE)
pCfg->walCfg.encryptAlgorithm = pCreate->encryptAlgorithm; pCfg->walCfg.encryptAlgorithm = pCreate->encryptAlgorithm;
if (pCfg->walCfg.encryptAlgorithm == DND_CA_SM4) { if (pCfg->walCfg.encryptAlgorithm == DND_CA_SM4) {
tstrncpy(pCfg->walCfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); tstrncpy(pCfg->walCfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN + 1);
} }
#else #else
pCfg->walCfg.encryptAlgorithm = 0; pCfg->walCfg.encryptAlgorithm = 0;
@ -211,7 +211,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
#if defined(TD_ENTERPRISE) #if defined(TD_ENTERPRISE)
pCfg->tdbEncryptAlgorithm = pCreate->encryptAlgorithm; pCfg->tdbEncryptAlgorithm = pCreate->encryptAlgorithm;
if (pCfg->tdbEncryptAlgorithm == DND_CA_SM4) { if (pCfg->tdbEncryptAlgorithm == DND_CA_SM4) {
tstrncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); strncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
} }
#else #else
pCfg->tdbEncryptAlgorithm = 0; pCfg->tdbEncryptAlgorithm = 0;

View File

@ -349,7 +349,7 @@ static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) {
} }
SCryptOpts opts = {0}; SCryptOpts opts = {0};
tstrncpy(opts.key, key, ENCRYPT_KEY_LEN); strncpy(opts.key, key, ENCRYPT_KEY_LEN);
opts.len = len; opts.len = len;
opts.source = content; opts.source = content;
opts.result = result; opts.result = result;
@ -551,7 +551,7 @@ int32_t dmGetEncryptKey() {
goto _OVER; goto _OVER;
} }
tstrncpy(tsEncryptKey, encryptKey, ENCRYPT_KEY_LEN); strncpy(tsEncryptKey, encryptKey, ENCRYPT_KEY_LEN + 1);
taosMemoryFreeClear(encryptKey); taosMemoryFreeClear(encryptKey);
tsEncryptionKeyChksum = taosCalcChecksum(0, tsEncryptKey, strlen(tsEncryptKey)); tsEncryptionKeyChksum = taosCalcChecksum(0, tsEncryptKey, strlen(tsEncryptKey));
tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED; tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED;

View File

@ -1706,8 +1706,8 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate
if (pCreate->isImport != 1) { if (pCreate->isImport != 1) {
taosEncryptPass_c((uint8_t *)pCreate->pass, strlen(pCreate->pass), userObj.pass); taosEncryptPass_c((uint8_t *)pCreate->pass, strlen(pCreate->pass), userObj.pass);
} else { } else {
// mInfo("pCreate->pass:%s", pCreate->pass) // mInfo("pCreate->pass:%s", pCreate->eass)
tstrncpy(userObj.pass, pCreate->pass, TSDB_PASSWORD_LEN); memcpy(userObj.pass, pCreate->pass, TSDB_PASSWORD_LEN);
} }
tstrncpy(userObj.user, pCreate->user, TSDB_USER_LEN); tstrncpy(userObj.user, pCreate->user, TSDB_USER_LEN);
tstrncpy(userObj.acct, acct, TSDB_USER_LEN); tstrncpy(userObj.acct, acct, TSDB_USER_LEN);

View File

@ -370,7 +370,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
opts.source = pRaw->pData; opts.source = pRaw->pData;
opts.result = plantContent; opts.result = plantContent;
opts.unitLen = 16; opts.unitLen = 16;
tstrncpy(opts.key, tsEncryptKey, ENCRYPT_KEY_LEN); tstrncpy(opts.key, tsEncryptKey, ENCRYPT_KEY_LEN + 1);
count = CBC_Decrypt(&opts); count = CBC_Decrypt(&opts);

View File

@ -175,7 +175,7 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e
opts.result = PacketData; opts.result = PacketData;
opts.unitLen = 128; opts.unitLen = 128;
// strncpy(opts.key, tsEncryptKey, 16); // strncpy(opts.key, tsEncryptKey, 16);
tstrncpy(opts.key, encryptKey, ENCRYPT_KEY_LEN); tstrncpy(opts.key, encryptKey, ENCRYPT_KEY_LEN + 1);
NewLen = CBC_Encrypt(&opts); NewLen = CBC_Encrypt(&opts);

View File

@ -265,7 +265,7 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
if (tsEncryptKey[0] == 0) { if (tsEncryptKey[0] == 0) {
return terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY; return terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
} else { } else {
tstrncpy(pCfg->tsdbCfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); tstrncpy(pCfg->tsdbCfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN + 1);
} }
} }
#endif #endif
@ -292,7 +292,7 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
if (tsEncryptKey[0] == 0) { if (tsEncryptKey[0] == 0) {
return terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY; return terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
} else { } else {
tstrncpy(pCfg->walCfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); tstrncpy(pCfg->walCfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN + 1);
} }
} }
#endif #endif
@ -303,7 +303,7 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
if (tsEncryptKey[0] == 0) { if (tsEncryptKey[0] == 0) {
return terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY; return terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
} else { } else {
tstrncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); strncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
} }
} }
#endif #endif

View File

@ -1199,6 +1199,7 @@ int32_t taskDbLoadChkpInfo(STaskDbWrapper* pBackend) {
nBytes = snprintf(pChkpDir, cap, "%s%s%s", pBackend->path, TD_DIRSEP, "checkpoints"); nBytes = snprintf(pChkpDir, cap, "%s%s%s", pBackend->path, TD_DIRSEP, "checkpoints");
if (nBytes >= cap) { if (nBytes >= cap) {
taosMemoryFree(pChkpDir);
return TSDB_CODE_OUT_OF_RANGE; return TSDB_CODE_OUT_OF_RANGE;
} }
if (!taosIsDir(pChkpDir)) { if (!taosIsDir(pChkpDir)) {

View File

@ -691,7 +691,7 @@ int32_t syncGetArbToken(int64_t rid, char* outToken) {
memset(outToken, 0, TSDB_ARB_TOKEN_SIZE); memset(outToken, 0, TSDB_ARB_TOKEN_SIZE);
(void)taosThreadMutexLock(&pSyncNode->arbTokenMutex); (void)taosThreadMutexLock(&pSyncNode->arbTokenMutex);
tstrncpy(outToken, pSyncNode->arbToken, TSDB_ARB_TOKEN_SIZE); strncpy(outToken, pSyncNode->arbToken, TSDB_ARB_TOKEN_SIZE);
(void)taosThreadMutexUnlock(&pSyncNode->arbTokenMutex); (void)taosThreadMutexUnlock(&pSyncNode->arbTokenMutex);
syncNodeRelease(pSyncNode); syncNodeRelease(pSyncNode);

View File

@ -52,7 +52,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, i
pDb->encryptAlgorithm = encryptAlgorithm; pDb->encryptAlgorithm = encryptAlgorithm;
if (encryptKey != NULL) { if (encryptKey != NULL) {
tstrncpy(pDb->encryptKey, encryptKey, ENCRYPT_KEY_LEN); tstrncpy(pDb->encryptKey, encryptKey, ENCRYPT_KEY_LEN + 1);
} }
ret = tdbPCacheOpen(szPage, pages, &(pDb->pCache)); ret = tdbPCacheOpen(szPage, pages, &(pDb->pCache));

View File

@ -459,7 +459,7 @@ static char *tdbEncryptPage(SPager *pPager, char *pPageData, int32_t pageSize, c
opts.source = pPageData + count; opts.source = pPageData + count;
opts.result = packetData; opts.result = packetData;
opts.unitLen = 128; opts.unitLen = 128;
tstrncpy(opts.key, encryptKey, ENCRYPT_KEY_LEN); tstrncpy(opts.key, encryptKey, ENCRYPT_KEY_LEN + 1);
int32_t newLen = CBC_Encrypt(&opts); int32_t newLen = CBC_Encrypt(&opts);
@ -927,7 +927,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
opts.source = pPage->pData + count; opts.source = pPage->pData + count;
opts.result = packetData; opts.result = packetData;
opts.unitLen = 128; opts.unitLen = 128;
tstrncpy(opts.key, encryptKey, ENCRYPT_KEY_LEN); tstrncpy(opts.key, encryptKey, ENCRYPT_KEY_LEN + 1);
int newLen = CBC_Decrypt(&opts); int newLen = CBC_Decrypt(&opts);