use safe sys func

This commit is contained in:
yihaoDeng 2024-12-06 21:44:23 +08:00
parent 66771b41a0
commit b9d92bd7b7
6 changed files with 57 additions and 64 deletions

View File

@ -220,6 +220,7 @@ int32_t dmInitVars(SDnode *pDnode) {
} }
extern SMonVloadInfo tsVinfo; extern SMonVloadInfo tsVinfo;
void dmClearVars(SDnode *pDnode) { void dmClearVars(SDnode *pDnode) {
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) { for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];

View File

@ -1884,7 +1884,7 @@ static int32_t mndMCfgGetValInt32(SMCfgDnodeReq *pMCfgReq, int32_t optLen, int32
if (strlen(pMCfgReq->value) != 0) goto _err; if (strlen(pMCfgReq->value) != 0) goto _err;
code = taosStr2int32(pMCfgReq->config + optLen + 1, pOutValue); code = taosStr2int32(pMCfgReq->config + optLen + 1, pOutValue);
if (code != 0) { if (code != 0) {
mError("dnode:%d, failed to get cfg since code: %s", pMCfgReq->dnodeId, tstrerror(code)); mError("dnode:%d, failed to get cfg since %s", pMCfgReq->dnodeId, tstrerror(code));
goto _err; goto _err;
} }
} else { } else {
@ -1892,7 +1892,7 @@ static int32_t mndMCfgGetValInt32(SMCfgDnodeReq *pMCfgReq, int32_t optLen, int32
if (strlen(pMCfgReq->value) == 0) goto _err; if (strlen(pMCfgReq->value) == 0) goto _err;
code = taosStr2int32(pMCfgReq->value, pOutValue); code = taosStr2int32(pMCfgReq->value, pOutValue);
if (code != 0) { if (code != 0) {
mError("dnode:%d, failed to get cfg since code: %s", pMCfgReq->dnodeId, tstrerror(code)); mError("dnode:%d, failed to get cfg since %s", pMCfgReq->dnodeId, tstrerror(code));
goto _err; goto _err;
} }
} }

View File

@ -530,7 +530,7 @@ static int32_t mndInitWal(SMnode *pMnode) {
code = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY; code = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
TAOS_RETURN(code); TAOS_RETURN(code);
} else { } else {
tstrncpy(cfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); tstrncpy(cfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN + 1);
} }
} }
#endif #endif

View File

@ -638,7 +638,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
opts.source = newBody; opts.source = newBody;
opts.result = newBodyEncrypted; opts.result = newBodyEncrypted;
opts.unitLen = 16; opts.unitLen = 16;
tstrncpy((char *)opts.key, pWal->cfg.encryptKey, ENCRYPT_KEY_LEN); tstrncpy((char *)opts.key, pWal->cfg.encryptKey, ENCRYPT_KEY_LEN + 1);
int32_t count = CBC_Encrypt(&opts); int32_t count = CBC_Encrypt(&opts);

View File

@ -123,10 +123,8 @@ int32_t taosStr2int64(const char *str, int64_t *val) {
errno = 0; errno = 0;
char *endptr = NULL; char *endptr = NULL;
int64_t ret = strtoll(str, &endptr, 10); int64_t ret = strtoll(str, &endptr, 10);
if (errno == ERANGE && (ret == LLONG_MAX || ret == LLONG_MIN)) { if (errno != 0) {
return TAOS_SYSTEM_ERROR(errno); return TAOS_SYSTEM_ERROR(errno);
} else if (errno == EINVAL && ret == 0) {
return TSDB_CODE_INVALID_PARA;
} else { } else {
if (endptr == str) { if (endptr == str) {
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
@ -187,12 +185,11 @@ int32_t taosStr2Uint64(const char *str, uint64_t *val) {
char *endptr = NULL; char *endptr = NULL;
errno = 0; errno = 0;
uint64_t ret = strtoull(str, &endptr, 10); uint64_t ret = strtoull(str, &endptr, 10);
if (errno == ERANGE && (ret == ULLONG_MAX)) {
if (errno != 0) {
return TAOS_SYSTEM_ERROR(errno); return TAOS_SYSTEM_ERROR(errno);
} else if (errno == EINVAL && ret == 0) {
return TSDB_CODE_INVALID_PARA;
} else { } else {
if (str == endptr) { if (endptr == str) {
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
} }
*val = ret; *val = ret;

View File

@ -283,30 +283,25 @@ static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value,
tstrncpy(cfg.dir, pItem->str, sizeof(cfg.dir)); tstrncpy(cfg.dir, pItem->str, sizeof(cfg.dir));
code = taosStr2int32(level, &cfg.level); code = taosStr2int32(level, &cfg.level);
if (code != 0) { TAOS_CHECK_GOTO(code, NULL, _err);
cfg.level = 0;
}
code = taosStr2int32(primary, &cfg.primary); code = taosStr2int32(primary, &cfg.primary);
if (code != 0) { TAOS_CHECK_GOTO(code, NULL, _err);
cfg.primary = 1;
}
code = taosStr2int8(disable, &cfg.disable); code = taosStr2int8(disable, &cfg.disable);
if (code != 0) { TAOS_CHECK_GOTO(code, NULL, _err);
cfg.disable = 0;
}
void *ret = taosArrayPush(pItem->array, &cfg); void *ret = taosArrayPush(pItem->array, &cfg);
if (ret == NULL) { if (ret == NULL) {
(void)taosThreadMutexUnlock(&pCfg->lock); code = terrno;
TAOS_CHECK_GOTO(code, NULL, _err);
TAOS_RETURN(terrno);
} }
pItem->stype = stype; pItem->stype = stype;
(void)taosThreadMutexUnlock(&pCfg->lock); (void)taosThreadMutexUnlock(&pCfg->lock);
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
_err:
(void)taosThreadMutexUnlock(&pCfg->lock);
TAOS_RETURN(code);
} }
static int32_t cfgUpdateDebugFlagItem(SConfig *pCfg, const char *name, bool resetArray) { static int32_t cfgUpdateDebugFlagItem(SConfig *pCfg, const char *name, bool resetArray) {