diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index c03e3be4ed..24e0f48ec9 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -285,8 +285,8 @@ typedef struct STscObj { void * pTimer; char user[TSDB_USER_LEN]; char pass[TSDB_KEY_LEN]; - char acctId[TSDB_DB_NAME_LEN]; - char db[TSDB_TABLE_ID_LEN]; + char acctId[TSDB_ACCT_LEN]; + char db[TSDB_DB_NAME_LEN]; char sversion[TSDB_VERSION_LEN]; char writeAuth : 1; char superAuth : 1; diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 91e51f16ed..295b691275 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -286,7 +286,7 @@ static void tscProcessCurrentUser(SSqlObj *pSql) { } static void tscProcessCurrentDB(SSqlObj *pSql) { - char db[TSDB_DB_NAME_LEN + 1] = {0}; + char db[TSDB_DB_NAME_LEN] = {0}; extractDBName(pSql->pTscObj->db, db); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index ba714f10e4..ef22333836 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1041,7 +1041,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL /* db name is not specified, the tableName dose not include db name */ if (pDB != NULL) { - if (pDB->n > TSDB_DB_NAME_LEN) { + if (pDB->n >= TSDB_DB_NAME_LEN) { return TSDB_CODE_TSC_INVALID_SQL; } @@ -1060,7 +1060,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL } } else { // pDB == NULL, the db prefix name is specified in tableName /* the length limitation includes tablename + dbname + sep */ - if (tableName->n > TSDB_TABLE_NAME_LEN + TSDB_DB_NAME_LEN + tListLen(TS_PATH_DELIMITER)) { + if (tableName->n > (TSDB_TABLE_NAME_LEN - 1) + (TSDB_DB_NAME_LEN - 1) + sizeof(TS_PATH_DELIMITER)) { return TSDB_CODE_TSC_INVALID_SQL; } } @@ -2202,7 +2202,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pDbPrefixToken->type != 0) { assert(pDbPrefixToken->n >= 0); - if (pDbPrefixToken->n > TSDB_DB_NAME_LEN) { // db name is too long + if (pDbPrefixToken->n >= TSDB_DB_NAME_LEN) { // db name is too long return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index aab931cf93..723f03e964 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -92,15 +92,15 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con if (db) { int32_t len = strlen(db); /* db name is too long */ - if (len > TSDB_DB_NAME_LEN) { + if (len >= TSDB_DB_NAME_LEN) { terrno = TSDB_CODE_TSC_INVALID_DB_LENGTH; rpcClose(pDnodeConn); free(pObj); return NULL; } - char tmp[TSDB_DB_NAME_LEN + 1] = {0}; - strcpy(tmp, db); + char tmp[TSDB_DB_NAME_LEN] = {0}; + tstrncpy(tmp, db, sizeof(tmp)); strdequote(tmp); strtolower(pObj->db, tmp); diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index e010f7fe56..12754b164b 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -708,7 +708,7 @@ static void doInitGlobalConfig() { cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; cfg.minValue = 0; cfg.maxValue = 0; - cfg.ptrLength = TSDB_DB_NAME_LEN; + cfg.ptrLength = TSDB_DB_NAME_LEN - 1; cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); @@ -923,7 +923,7 @@ static void doInitGlobalConfig() { cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; cfg.minValue = 0; cfg.maxValue = 0; - cfg.ptrLength = TSDB_DB_NAME_LEN; + cfg.ptrLength = TSDB_DB_NAME_LEN - 1; cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index c1d0e5ae47..b0e01e087e 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -189,7 +189,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_USERID_LEN 9 #define TS_PATH_DELIMITER_LEN 1 -#define TSDB_METER_ID_LEN_MARGIN 9 +#define TSDB_METER_ID_LEN_MARGIN 8 #define TSDB_TABLE_ID_LEN (TSDB_DB_NAME_LEN+TSDB_TABLE_NAME_LEN+2*TS_PATH_DELIMITER_LEN+TSDB_USERID_LEN+TSDB_METER_ID_LEN_MARGIN) //TSDB_DB_NAME_LEN+TSDB_TABLE_NAME_LEN+2*strlen(TS_PATH_DELIMITER)+strlen(USERID) #define TSDB_UNI_LEN 24 #define TSDB_USER_LEN TSDB_UNI_LEN @@ -201,7 +201,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_NODE_NAME_LEN 64 #define TSDB_TABLE_NAME_LEN 193 -#define TSDB_DB_NAME_LEN 32 +#define TSDB_DB_NAME_LEN 33 #define TSDB_COL_NAME_LEN 64 #define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64 #define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 88c6f9cf26..c85bb229b9 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -250,7 +250,7 @@ typedef struct { typedef struct { char tableId[TSDB_TABLE_ID_LEN + 1]; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; int8_t igExists; int8_t getMeta; int16_t numOfTags; @@ -268,7 +268,7 @@ typedef struct { typedef struct { char tableId[TSDB_TABLE_ID_LEN + 1]; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; int16_t type; /* operation type */ int16_t numOfCols; /* number of schema */ int32_t tagValLen; @@ -502,7 +502,7 @@ typedef struct { typedef struct { char acct[TSDB_USER_LEN + 1]; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; int32_t cacheBlockSize; //MB int32_t totalBlocks; int32_t maxTables; @@ -606,7 +606,7 @@ typedef struct { } SMDVnodeDesc; typedef struct { - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; SMDVnodeCfg cfg; SMDVnodeDesc nodes[TSDB_MAX_REPLICA]; } SMDCreateVnodeMsg; @@ -671,7 +671,7 @@ typedef struct { */ typedef struct { int8_t type; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; uint16_t payloadLen; char payload[]; } SCMShowMsg; diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index d96f80ed20..c588dce20d 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -102,7 +102,7 @@ typedef struct { extern char version[]; typedef struct { - char name[TSDB_DB_NAME_LEN + 1]; + char name[TSDB_DB_NAME_LEN]; int32_t replica; int32_t days; int32_t keep; diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index cf9058b9cf..35ae9aad33 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -115,7 +115,7 @@ typedef struct { typedef struct SVgObj { uint32_t vgId; - char dbName[TSDB_DB_NAME_LEN + 1]; + char dbName[TSDB_DB_NAME_LEN]; int64_t createdTime; SVnodeGid vnodeGid[TSDB_MAX_REPLICA]; int32_t numOfVnodes; @@ -154,7 +154,7 @@ typedef struct { } SDbCfg; typedef struct SDbObj { - char name[TSDB_DB_NAME_LEN + 1]; + char name[TSDB_DB_NAME_LEN]; char acct[TSDB_USER_LEN + 1]; int64_t createdTime; int32_t cfgVersion; @@ -219,7 +219,7 @@ typedef struct SAcctObj { typedef struct { int8_t type; int32_t index; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; void * pIter; int16_t numOfColumns; int32_t rowSize; diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 90569b4a95..c80dc3036f 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -328,8 +328,8 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { if (code != 0) return code; pDb = calloc(1, sizeof(SDbObj)); - strncpy(pDb->name, pCreate->db, TSDB_DB_NAME_LEN); - strncpy(pDb->acct, pAcct->user, TSDB_USER_LEN); + tstrncpy(pDb->name, pCreate->db, sizeof(pDb->name)); + tstrncpy(pDb->acct, pAcct->user, sizeof(pDb->acct)); pDb->createdTime = taosGetTimestampMs(); pDb->cfg = (SDbCfg) { .cacheBlockSize = pCreate->cacheBlockSize, @@ -373,7 +373,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { } bool mnodeCheckIsMonitorDB(char *db, char *monitordb) { - char dbName[TSDB_DB_NAME_LEN + 1] = {0}; + char dbName[TSDB_DB_NAME_LEN] = {0}; extractDBName(db, dbName); size_t len = strlen(dbName); @@ -453,7 +453,7 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - pShow->bytes[cols] = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE; + pShow->bytes[cols] = (TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "name"); pSchema[cols].bytes = htons(pShow->bytes[cols]); @@ -610,7 +610,7 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; char* name = mnodeGetDbStr(pDb->name); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, TSDB_DB_NAME_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, TSDB_DB_NAME_LEN - 1); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index b9033cdf3c..8d74827841 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -43,7 +43,7 @@ typedef enum { } ESdbStatus; typedef struct _SSdbTable { - char tableName[TSDB_DB_NAME_LEN + 1]; + char tableName[TSDB_DB_NAME_LEN]; ESdbTable tableId; ESdbKey keyType; int32_t hashSessions; diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 54a6c2c7c0..ac826c9781 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -1160,7 +1160,7 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - int16_t len = strnlen(stableName, TSDB_DB_NAME_LEN); + int16_t len = strnlen(stableName, TSDB_DB_NAME_LEN - 1); *(int16_t*) pWrite = len; pWrite += sizeof(int16_t); // todo refactor diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index b080de87f2..09fed07573 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -6037,9 +6037,9 @@ static void buildTagQueryResult(SQInfo* pQInfo) { for(int32_t j = 0; j < pQuery->numOfOutput; ++j) { if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { - data = tsdbGetTableName(pQInfo->tsdb, &item->id, &bytes); + char* data = tsdbGetTableName(pQInfo->tsdb, &item->id); - char* dst = pQuery->sdata[j]->data + i * ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE); + char* dst = pQuery->sdata[j]->data + count * ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE); memcpy(dst, data, varDataTLen(data)); } else {// todo refactor int16_t type = pExprInfo[j].type; diff --git a/src/vnode/inc/vnodeInt.h b/src/vnode/inc/vnodeInt.h index 7c95e81cf5..ab74e329e6 100644 --- a/src/vnode/inc/vnodeInt.h +++ b/src/vnode/inc/vnodeInt.h @@ -51,7 +51,7 @@ typedef struct { SSyncCfg syncCfg; SWalCfg walCfg; char *rootDir; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; } SVnodeObj; int vnodeWriteToQueue(void *param, void *pHead, int type);