Merge pull request #29153 from taosdata/fix/3.0/TD-33220

Fix(cfg): fulltest make problems and add check for cfg str len.
This commit is contained in:
Shengliang Guan 2024-12-16 21:31:37 +08:00 committed by GitHub
commit 4490d73d61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 51 additions and 14 deletions

View File

@ -24,7 +24,7 @@ extern "C" {
#endif
int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t cfgNameMaxLen);
int32_t taosEnvToCfg(const char *envStr, char *cfgStr);
int32_t taosEnvToCfg(const char *envStr, char *cfgStr,int32_t cfgStrLen);
#ifdef __cplusplus
}

View File

@ -14,12 +14,12 @@
*/
#define _DEFAULT_SOURCE
#include "tglobal.h"
#include "cJSON.h"
#include "defines.h"
#include "os.h"
#include "osString.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tgrant.h"
#include "tjson.h"
#include "tlog.h"
@ -359,6 +359,8 @@ int32_t tsMaxTsmaCalcDelay = 600;
int64_t tsmaDataDeleteMark = 1000 * 60 * 60 * 24; // in ms, default to 1d
void *pTimezoneNameMap = NULL;
int32_t taosCheckCfgStrValueLen(const char *name, const char *value, int32_t len);
#define TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, pName) \
if ((pItem = cfgGetItem(pCfg, pName)) == NULL) { \
TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); \
@ -449,6 +451,7 @@ int32_t taosSetS3Cfg(SConfig *pCfg) {
SConfigItem *pItem = NULL;
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "s3BucketName");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen("s3BucketName", pItem->str, TSDB_FQDN_LEN));
tstrncpy(tsS3BucketName, pItem->str, TSDB_FQDN_LEN);
for (int i = 0; i < tsS3EpNum; ++i) {
@ -1153,6 +1156,7 @@ static int32_t taosSetClientLogCfg(SConfig *pCfg) {
SConfigItem *pItem = NULL;
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "logDir");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, PATH_MAX));
tstrncpy(tsLogDir, pItem->str, PATH_MAX);
TAOS_CHECK_RETURN(taosExpandDir(tsLogDir, tsLogDir, PATH_MAX));
TAOS_CHECK_RETURN(taosSetLogOutput(pCfg));
@ -1303,6 +1307,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
SConfigItem *pItem = NULL;
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "fqdn");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_FQDN_LEN));
tstrncpy(tsLocalFqdn, pItem->str, TSDB_FQDN_LEN);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "forceReadConfig");
@ -1328,6 +1333,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
TAOS_CHECK_RETURN(cfgSetItem(pCfg, "secondEp", tsSecond, pItem->stype, true));
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "tempDir");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, PATH_MAX));
tstrncpy(tsTempDir, pItem->str, PATH_MAX);
TAOS_CHECK_RETURN(taosExpandDir(tsTempDir, tsTempDir, PATH_MAX));
@ -1340,15 +1346,19 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
}
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "smlAutoChildTableNameDelimiter");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_TABLE_NAME_LEN));
tstrncpy(tsSmlAutoChildTableNameDelimiter, pItem->str, TSDB_TABLE_NAME_LEN);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "smlChildTableName");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_TABLE_NAME_LEN));
tstrncpy(tsSmlChildTableName, pItem->str, TSDB_TABLE_NAME_LEN);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "smlTagName");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_COL_NAME_LEN));
tstrncpy(tsSmlTagName, pItem->str, TSDB_COL_NAME_LEN);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "smlTsDefaultName");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_COL_NAME_LEN));
tstrncpy(tsSmlTsDefaultName, pItem->str, TSDB_COL_NAME_LEN);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "smlDot2Underline");
@ -1495,9 +1505,11 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tsQueryBufferSize = pItem->i32;
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "encryptAlgorithm");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, 16));
tstrncpy(tsEncryptAlgorithm, pItem->str, 16);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "encryptScope");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, 100));
tstrncpy(tsEncryptScope, pItem->str, 100);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfRpcThreads");
@ -1561,6 +1573,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tsTagFilterCache = (bool)pItem->bval;
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "slowLogExceptDb");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_DB_NAME_LEN));
tstrncpy(tsSlowLogExceptDb, pItem->str, TSDB_DB_NAME_LEN);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "slowLogThreshold");
@ -1581,6 +1594,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tsMonitorInterval = pItem->i32;
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "monitorFqdn");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_FQDN_LEN));
tstrncpy(tsMonitorFqdn, pItem->str, TSDB_FQDN_LEN);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "monitorPort");
@ -1632,12 +1646,15 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tsRsyncPort = pItem->i32;
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "telemetryServer");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_FQDN_LEN));
tstrncpy(tsTelemServer, pItem->str, TSDB_FQDN_LEN);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "snodeAddress");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_FQDN_LEN));
tstrncpy(tsSnodeAddress, pItem->str, TSDB_FQDN_LEN);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "checkpointBackupDir");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, PATH_MAX));
tstrncpy(tsCheckpointBackupDir, pItem->str, PATH_MAX);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "telemetryPort");
@ -1728,9 +1745,11 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tsStartUdfd = pItem->bval;
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "udfdResFuncs");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, sizeof(tsUdfdResFuncs)));
tstrncpy(tsUdfdResFuncs, pItem->str, sizeof(tsUdfdResFuncs));
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "udfdLdLibPath");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, sizeof(tsUdfdLdLibPath)));
tstrncpy(tsUdfdLdLibPath, pItem->str, sizeof(tsUdfdLdLibPath));
if (tsQueryBufferSize >= 0) {
tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL;
@ -1755,6 +1774,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tsIfAdtFse = pItem->bval;
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "compressor");
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, sizeof(tsCompressor)));
tstrncpy(tsCompressor, pItem->str, sizeof(tsCompressor));
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "disableStream");
@ -2295,9 +2315,15 @@ static int32_t taosCfgSetOption(OptionNameAndVar *pOptions, int32_t optionSize,
case CFG_DTYPE_LOCALE:
case CFG_DTYPE_CHARSET:
case CFG_DTYPE_TIMEZONE: {
char *pVar = pOptions[d].optionVar;
tstrncpy(pVar, pItem->str, strlen(pItem->str));
uInfo("%s set to %s", optName, pVar);
if (strcasecmp(pItem->name, "slowLogExceptDb") == 0) {
TAOS_CHECK_RETURN(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_DB_NAME_LEN));
tstrncpy(tsSlowLogExceptDb, pItem->str, TSDB_DB_NAME_LEN);
} else {
uError("not support string type for %s", optName);
code = TSDB_CODE_INVALID_CFG;
break;
}
uInfo("%s set to %s", optName, pItem->str);
} break;
default:
code = TSDB_CODE_INVALID_CFG;
@ -2439,9 +2465,6 @@ static int32_t taosCfgDynamicOptionsForServer(SConfig *pCfg, const char *name) {
{"ttlFlushThreshold", &tsTtlFlushThreshold},
{"ttlPushInterval", &tsTtlPushIntervalSec},
{"ttlUnit", &tsTtlUnit},
{"s3Accesskey", &tsS3AccessKey},
{"s3BucketName", &tsS3BucketName},
{"s3Endpoint", &tsS3Endpoint},
{"s3MigrateIntervalSec", &tsS3MigrateIntervalSec},
{"s3MigrateEnabled", &tsS3MigrateEnabled},
//{"s3BlockSize", &tsS3BlockSize},
@ -2610,18 +2633,22 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) {
uInfo("%s set to %s", name, tsSecond);
matched = true;
} else if (strcasecmp("smlChildTableName", name) == 0) {
TAOS_CHECK_GOTO(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_TABLE_NAME_LEN), &lino, _out);
uInfo("%s set from %s to %s", name, tsSmlChildTableName, pItem->str);
tstrncpy(tsSmlChildTableName, pItem->str, TSDB_TABLE_NAME_LEN);
matched = true;
} else if (strcasecmp("smlAutoChildTableNameDelimiter", name) == 0) {
TAOS_CHECK_GOTO(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_TABLE_NAME_LEN), &lino, _out);
uInfo("%s set from %s to %s", name, tsSmlAutoChildTableNameDelimiter, pItem->str);
tstrncpy(tsSmlAutoChildTableNameDelimiter, pItem->str, TSDB_TABLE_NAME_LEN);
matched = true;
} else if (strcasecmp("smlTagName", name) == 0) {
TAOS_CHECK_GOTO(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_COL_NAME_LEN), &lino, _out);
uInfo("%s set from %s to %s", name, tsSmlTagName, pItem->str);
tstrncpy(tsSmlTagName, pItem->str, TSDB_COL_NAME_LEN);
matched = true;
} else if (strcasecmp("smlTsDefaultName", name) == 0) {
TAOS_CHECK_GOTO(taosCheckCfgStrValueLen(pItem->name, pItem->str, TSDB_COL_NAME_LEN), &lino, _out);
uInfo("%s set from %s to %s", name, tsSmlTsDefaultName, pItem->str);
tstrncpy(tsSmlTsDefaultName, pItem->str, TSDB_COL_NAME_LEN);
matched = true;
@ -2635,6 +2662,7 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) {
goto _out;
}
TAOS_CHECK_GOTO(taosCheckCfgStrValueLen(pFqdnItem->name, pFqdnItem->str, TSDB_FQDN_LEN), &lino, _out);
tstrncpy(tsLocalFqdn, pFqdnItem->str, TSDB_FQDN_LEN);
tsServerPort = (uint16_t)pServerPortItem->i32;
(void)snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort);
@ -2656,6 +2684,7 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) {
}
case 't': {
if (strcasecmp("tempDir", name) == 0) {
TAOS_CHECK_GOTO(taosCheckCfgStrValueLen(pItem->name, pItem->str, PATH_MAX), &lino, _out);
uInfo("%s set from %s to %s", name, tsTempDir, pItem->str);
tstrncpy(tsTempDir, pItem->str, PATH_MAX);
TAOS_CHECK_GOTO(taosExpandDir(tsTempDir, tsTempDir, PATH_MAX), &lino, _out);
@ -3223,3 +3252,11 @@ bool isConifgItemLazyMode(SConfigItem *item) {
}
return false;
}
int32_t taosCheckCfgStrValueLen(const char *name, const char *value, int32_t len) {
if (strlen(value) > len) {
uError("invalid config:%s, value:%s, length should be less than %d", name, value, len);
TAOS_RETURN(TSDB_CODE_INVALID_CFG_VALUE);
}
TAOS_RETURN(TSDB_CODE_SUCCESS);
}

View File

@ -1201,7 +1201,7 @@ int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
tstrncpy(line, *pEnv, sizeof(line));
pEnv++;
if (taosEnvToCfg(line, line) < 0) {
if (taosEnvToCfg(line, line, 1024) < 0) {
uTrace("failed to convert env to cfg:%s", line);
}
@ -1246,7 +1246,7 @@ int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) {
while (envCmd[index] != NULL) {
tstrncpy(buf, envCmd[index], sizeof(buf));
buf[sizeof(buf) - 1] = 0;
if (taosEnvToCfg(buf, buf) < 0) {
if (taosEnvToCfg(buf, buf, 1024) < 0) {
uTrace("failed to convert env to cfg:%s", buf);
}
index++;
@ -1320,7 +1320,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
break;
}
if (line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
if (taosEnvToCfg(line, line) < 0) {
if (taosEnvToCfg(line, line, 1024) < 0) {
uTrace("failed to convert env to cfg:%s", line);
}

View File

@ -14,8 +14,8 @@
*/
#define _DEFAULT_SOURCE
#include "tenv.h"
#include "tconfig.h"
#include "tenv.h"
static char toLowChar(char c) { return (c > 'Z' || c < 'A' ? c : (c - 'A' + 'a')); }
@ -50,12 +50,12 @@ int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t c
return strlen(cfgNameStr);
}
int32_t taosEnvToCfg(const char *envStr, char *cfgStr) {
int32_t taosEnvToCfg(const char *envStr, char *cfgStr, int32_t cfgStrLen) {
if (envStr == NULL || cfgStr == NULL) {
return TSDB_CODE_INVALID_PARA;
}
if (cfgStr != envStr) {
tstrncpy(cfgStr, envStr, strlen(envStr) + 1);
tstrncpy(cfgStr, envStr, cfgStrLen);
}
char *p = strchr(cfgStr, '=');