Skip to content

Commit 3497aab

Browse files
authored
Merge pull request #29185 from taosdata/enh/TD-32406-main
enh: memory safe function
2 parents 2e2897f + 973a2ac commit 3497aab

File tree

7 files changed

+7
-7
lines changed

7 files changed

+7
-7
lines changed

include/libs/crypt/crypt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef struct SCryptOpts {
2626
char* source;
2727
char* result;
2828
int32_t unitLen;
29-
char key[17];
29+
char key[ENCRYPT_KEY_LEN + 1];
3030
} SCryptOpts;
3131

3232
int32_t CBC_Decrypt(SCryptOpts* opts);

source/dnode/mgmt/mgmt_vnode/src/vmHandle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
211211
#if defined(TD_ENTERPRISE)
212212
pCfg->tdbEncryptAlgorithm = pCreate->encryptAlgorithm;
213213
if (pCfg->tdbEncryptAlgorithm == DND_CA_SM4) {
214-
tstrncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
214+
tstrncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN + 1);
215215
}
216216
#else
217217
pCfg->tdbEncryptAlgorithm = 0;

source/dnode/vnode/inc/vnode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ struct SVnodeCfg {
327327
int16_t hashSuffix;
328328
int32_t tsdbPageSize;
329329
int32_t tdbEncryptAlgorithm;
330-
char tdbEncryptKey[ENCRYPT_KEY_LEN];
330+
char tdbEncryptKey[ENCRYPT_KEY_LEN + 1];
331331
int32_t s3ChunkSize;
332332
int32_t s3KeepLocal;
333333
int8_t s3Compact;

source/dnode/vnode/src/tsdb/tsdbReaderWriter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int32_t tsdbOpenFile(const char *path, STsdb *pTsdb, int32_t flag, STsdbFD **ppF
104104
}
105105

106106
pFD->path = (char *)&pFD[1];
107-
tstrncpy(pFD->path, path, strlen(path) + 1);
107+
memcpy(pFD->path, path, strlen(path) + 1);
108108
pFD->szPage = szPage;
109109
pFD->flag = flag;
110110
pFD->szPage = szPage;

source/dnode/vnode/src/vnd/vnodeAsync.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static int32_t vnodeAsyncInit(SVAsync **async, const char *label) {
330330
return terrno;
331331
}
332332

333-
tstrncpy((char *)((*async) + 1), label, strlen(label) + 1);
333+
memcpy((char *)((*async) + 1), label, strlen(label) + 1);
334334
(*async)->label = (const char *)((*async) + 1);
335335

336336
(void)taosThreadMutexInit(&(*async)->mutex, NULL);

source/dnode/vnode/src/vnd/vnodeCfg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
303303
if (tsEncryptKey[0] == 0) {
304304
return terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
305305
} else {
306-
tstrncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
306+
tstrncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN + 1);
307307
}
308308
}
309309
#endif

source/dnode/vnode/src/vnd/vnodeOpen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC
417417
}
418418

419419
pVnode->path = (char *)&pVnode[1];
420-
tstrncpy(pVnode->path, path, strlen(path) + 1);
420+
memcpy(pVnode->path, path, strlen(path) + 1);
421421
pVnode->config = info.config;
422422
pVnode->state.committed = info.state.committed;
423423
pVnode->state.commitTerm = info.state.commitTerm;

0 commit comments

Comments
 (0)