From b81f715849122729fe1ea324bd8d6e3101728b4b Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 10 Jun 2020 09:47:26 +0800 Subject: [PATCH 1/6] TD-459: TSDB_IPv4ADDR_LEN --- src/client/src/tscSQLParser.c | 2 +- src/mnode/src/mnodeProfile.c | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 9acf213171..528c936e12 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2241,7 +2241,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { // show vnodes may be ip addr of dnode in payload SSQLToken* pDnodeIp = &pShowInfo->prefix; - if (pDnodeIp->n > TSDB_IPv4ADDR_LEN) { // ip addr is too long + if (pDnodeIp->n >= TSDB_IPv4ADDR_LEN) { // ip addr is too long return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); } diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index bfb92096ec..96bc98d659 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -222,7 +222,7 @@ static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, voi SConnObj *pConnObj = NULL; int32_t cols = 0; char * pWrite; - char ipStr[TSDB_IPv4ADDR_LEN + 7]; + char ipStr[TSDB_IPv4ADDR_LEN + 6]; while (numOfRows < rows) { pShow->pIter = mnodeGetNextConn(pShow->pIter, &pConnObj); @@ -239,8 +239,8 @@ static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, voi cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - snprintf(ipStr, TSDB_IPv4ADDR_LEN + 6, "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, TSDB_IPv4ADDR_LEN + 6); + snprintf(ipStr, sizeof(ipStr), "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, sizeof(ipStr)); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -342,7 +342,7 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v SConnObj *pConnObj = NULL; int32_t cols = 0; char * pWrite; - char ipStr[TSDB_IPv4ADDR_LEN + 7]; + char ipStr[TSDB_IPv4ADDR_LEN + 6]; while (numOfRows < rows) { pShow->pIter = mnodeGetNextConn(pShow->pIter, &pConnObj); @@ -362,8 +362,8 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - snprintf(ipStr, TSDB_IPv4ADDR_LEN + 6, "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, TSDB_IPv4ADDR_LEN + 6); + snprintf(ipStr, sizeof(ipStr), "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, sizeof(ipStr)); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -463,7 +463,7 @@ static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, v SConnObj *pConnObj = NULL; int32_t cols = 0; char * pWrite; - char ipStr[TSDB_IPv4ADDR_LEN + 7]; + char ipStr[TSDB_IPv4ADDR_LEN + 6]; while (numOfRows < rows) { pShow->pIter = mnodeGetNextConn(pShow->pIter, &pConnObj); @@ -483,8 +483,8 @@ static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, v cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - snprintf(ipStr, TSDB_IPv4ADDR_LEN + 6, "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, TSDB_IPv4ADDR_LEN + 6); + snprintf(ipStr, sizeof(ipStr), "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, sizeof(ipStr)); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; From 7f1232144a55faa75d7e522c0966c56a8a9a5f8c Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 10 Jun 2020 10:09:35 +0800 Subject: [PATCH 2/6] TD-459: TSDB_USER_LEN --- src/client/src/tscLocal.c | 2 +- src/client/src/tscSQLParser.c | 6 +++--- src/common/src/tglobal.c | 2 +- src/dnode/src/dnodeShell.c | 2 +- src/inc/taosmsg.h | 14 +++++++------- src/mnode/inc/mnodeDef.h | 10 +++++----- src/mnode/inc/mnodeProfile.h | 2 +- src/mnode/src/mnodeProfile.c | 8 ++++---- src/mnode/src/mnodeUser.c | 4 ++-- src/plugins/http/inc/httpHandle.h | 4 ++-- src/plugins/http/src/gcHandle.c | 2 +- src/plugins/http/src/httpAuth.c | 2 +- src/plugins/http/src/restHandle.c | 2 +- src/plugins/http/src/tgHandle.c | 4 ++-- src/plugins/monitor/src/monitorMain.c | 2 +- 15 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 52240941f2..f550bbd000 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -279,7 +279,7 @@ static void tscProcessCurrentUser(SSqlObj *pSql) { pExpr->resType = TSDB_DATA_TYPE_BINARY; char* vx = calloc(1, pExpr->resBytes); - STR_WITH_MAXSIZE_TO_VARSTR(vx, pSql->pTscObj->user, TSDB_USER_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(vx, pSql->pTscObj->user, sizeof(pSql->pTscObj->user)); tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes); free(vx); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 528c936e12..9c64786459 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -232,7 +232,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { pzName->n = strdequote(pzName->z); strncpy(pTableMetaInfo->name, pzName->z, pzName->n); } else { // drop user - if (pzName->n > TSDB_USER_LEN) { + if (pzName->n >= TSDB_USER_LEN) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); } @@ -317,7 +317,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { return TSDB_CODE_TSC_INVALID_SQL; } - if (pName->n > TSDB_USER_LEN) { + if (pName->n >= TSDB_USER_LEN) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); } @@ -401,7 +401,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { SSQLToken* pName = &pUser->user; SSQLToken* pPwd = &pUser->passwd; - if (pName->n > TSDB_USER_LEN) { + if (pName->n >= TSDB_USER_LEN) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); } diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 12754b164b..8c77f0b5f3 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -718,7 +718,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_USER_LEN; + cfg.ptrLength = TSDB_USER_LEN - 1; cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index 3f3c5f2796..4252e63f8d 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -147,7 +147,7 @@ static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char if (code != TSDB_CODE_RPC_NOT_READY) return code; SDMAuthMsg *pMsg = rpcMallocCont(sizeof(SDMAuthMsg)); - tstrncpy(pMsg->user, user, TSDB_USER_LEN); + tstrncpy(pMsg->user, user, sizeof(pMsg->user)); SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pMsg; diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 6a0219d6fc..0c47fad4dc 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -321,18 +321,18 @@ typedef struct { } SAcctCfg; typedef struct { - char user[TSDB_USER_LEN + 1]; - char pass[TSDB_KEY_LEN + 1]; + char user[TSDB_USER_LEN]; + char pass[TSDB_KEY_LEN]; SAcctCfg cfg; } SCMCreateAcctMsg, SCMAlterAcctMsg; typedef struct { - char user[TSDB_USER_LEN + 1]; + char user[TSDB_USER_LEN]; } SCMDropUserMsg, SCMDropAcctMsg; typedef struct { - char user[TSDB_USER_LEN + 1]; - char pass[TSDB_KEY_LEN + 1]; + char user[TSDB_USER_LEN]; + char pass[TSDB_KEY_LEN]; int8_t privilege; int8_t flag; } SCMCreateUserMsg, SCMAlterUserMsg; @@ -501,7 +501,7 @@ typedef struct { } SVnodeLoad; typedef struct { - char acct[TSDB_USER_LEN + 1]; + char acct[TSDB_USER_LEN]; char db[TSDB_DB_NAME_LEN]; int32_t cacheBlockSize; //MB int32_t totalBlocks; @@ -750,7 +750,7 @@ typedef struct { } SMDAlterStreamMsg; typedef struct { - char user[TSDB_USER_LEN + 1]; + char user[TSDB_USER_LEN]; char spi; char encrypt; char secret[TSDB_KEY_LEN + 1]; diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index 14cd405763..c60c221bcc 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -155,7 +155,7 @@ typedef struct { typedef struct SDbObj { char name[TSDB_DB_NAME_LEN]; - char acct[TSDB_USER_LEN + 1]; + char acct[TSDB_USER_LEN]; int64_t createdTime; int32_t cfgVersion; SDbCfg cfg; @@ -172,9 +172,9 @@ typedef struct SDbObj { } SDbObj; typedef struct SUserObj { - char user[TSDB_USER_LEN + 1]; - char pass[TSDB_KEY_LEN + 1]; - char acct[TSDB_USER_LEN + 1]; + char user[TSDB_USER_LEN]; + char pass[TSDB_KEY_LEN]; + char acct[TSDB_USER_LEN]; int64_t createdTime; int8_t superAuth; int8_t writeAuth; @@ -203,7 +203,7 @@ typedef struct { } SAcctInfo; typedef struct SAcctObj { - char user[TSDB_USER_LEN + 1]; + char user[TSDB_USER_LEN]; char pass[TSDB_KEY_LEN + 1]; SAcctCfg cfg; int32_t acctId; diff --git a/src/mnode/inc/mnodeProfile.h b/src/mnode/inc/mnodeProfile.h index 30745db035..c9f7cc8e2a 100644 --- a/src/mnode/inc/mnodeProfile.h +++ b/src/mnode/inc/mnodeProfile.h @@ -22,7 +22,7 @@ extern "C" { #include "mnodeDef.h" typedef struct { - char user[TSDB_USER_LEN + 1]; + char user[TSDB_USER_LEN]; int8_t killed; uint16_t port; uint32_t ip; diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index 96bc98d659..5b637d03bd 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -97,7 +97,7 @@ SConnObj *mnodeCreateConn(char *user, uint32_t ip, uint16_t port) { .connId = connId, .stime = taosGetTimestampMs() }; - tstrncpy(connObj.user, user, TSDB_USER_LEN); + tstrncpy(connObj.user, user, sizeof(connObj.user)); char key[10]; sprintf(key, "%u", connId); @@ -235,7 +235,7 @@ static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, voi cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, TSDB_USER_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, sizeof(pConnObj->user)); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -358,7 +358,7 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, TSDB_USER_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, sizeof(pConnObj->user)); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -479,7 +479,7 @@ static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, v cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, TSDB_USER_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, sizeof(pConnObj->user)); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index aab0847a6b..ee79d962ba 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -315,7 +315,7 @@ static int32_t mnodeRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, voi cols = 0; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pUser->user, TSDB_USER_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pUser->user, sizeof(pUser->user)); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -336,7 +336,7 @@ static int32_t mnodeRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, voi cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pUser->acct, TSDB_USER_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pUser->acct, sizeof(pUser->user)); cols++; numOfRows++; diff --git a/src/plugins/http/inc/httpHandle.h b/src/plugins/http/inc/httpHandle.h index 9be2796a96..b888543137 100644 --- a/src/plugins/http/inc/httpHandle.h +++ b/src/plugins/http/inc/httpHandle.h @@ -67,7 +67,7 @@ #define HTTP_COMPRESS_IDENTITY 0 #define HTTP_COMPRESS_GZIP 2 -#define HTTP_SESSION_ID_LEN (TSDB_USER_LEN * 2 + 1) +#define HTTP_SESSION_ID_LEN (TSDB_USER_LEN + TSDB_PASSWORD_LEN) typedef enum { HTTP_CONTEXT_STATE_READY, @@ -84,7 +84,7 @@ typedef struct { int expire; int access; void *taos; - char id[HTTP_SESSION_ID_LEN + 1]; + char id[HTTP_SESSION_ID_LEN]; } HttpSession; typedef enum { diff --git a/src/plugins/http/src/gcHandle.c b/src/plugins/http/src/gcHandle.c index 4120980123..a99059ea34 100644 --- a/src/plugins/http/src/gcHandle.c +++ b/src/plugins/http/src/gcHandle.c @@ -48,7 +48,7 @@ void gcInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &gcDecodeMethod) bool gcGetUserFromUrl(HttpContext* pContext) { HttpParser* pParser = &pContext->parser; - if (pParser->path[GC_USER_URL_POS].len > TSDB_USER_LEN - 1 || pParser->path[GC_USER_URL_POS].len <= 0) { + if (pParser->path[GC_USER_URL_POS].len >= TSDB_USER_LEN || pParser->path[GC_USER_URL_POS].len <= 0) { return false; } diff --git a/src/plugins/http/src/httpAuth.c b/src/plugins/http/src/httpAuth.c index ccf39642c9..752c7d1d50 100644 --- a/src/plugins/http/src/httpAuth.c +++ b/src/plugins/http/src/httpAuth.c @@ -101,7 +101,7 @@ bool httpParseTaosdAuthToken(HttpContext *pContext, char *token, int len) { bool httpGenTaosdAuthToken(HttpContext *pContext, char *token, int maxLen) { char buffer[TSDB_USER_LEN + TSDB_PASSWORD_LEN] = {0}; - strncpy(buffer, pContext->user, TSDB_USER_LEN); + strncpy(buffer, pContext->user, sizeof(pContext->user)); strncpy(buffer + TSDB_USER_LEN, pContext->pass, TSDB_PASSWORD_LEN); char *encrypt = taosDesEncode(KEY_DES_4, buffer, TSDB_USER_LEN + TSDB_PASSWORD_LEN); diff --git a/src/plugins/http/src/restHandle.c b/src/plugins/http/src/restHandle.c index d481a654d8..b9b096ac77 100644 --- a/src/plugins/http/src/restHandle.c +++ b/src/plugins/http/src/restHandle.c @@ -61,7 +61,7 @@ void restInitHandle(HttpServer* pServer) { bool restGetUserFromUrl(HttpContext* pContext) { HttpParser* pParser = &pContext->parser; - if (pParser->path[REST_USER_URL_POS].len > TSDB_USER_LEN - 1 || pParser->path[REST_USER_URL_POS].len <= 0) { + if (pParser->path[REST_USER_URL_POS].len >= TSDB_USER_LEN || pParser->path[REST_USER_URL_POS].len <= 0) { return false; } diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index 945eff7611..abc4acae65 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -306,11 +306,11 @@ void tgCleanupHandle() { bool tgGetUserFromUrl(HttpContext *pContext) { HttpParser *pParser = &pContext->parser; - if (pParser->path[TG_USER_URL_POS].len > TSDB_USER_LEN - 1 || pParser->path[TG_USER_URL_POS].len <= 0) { + if (pParser->path[TG_USER_URL_POS].len >= TSDB_USER_LEN || pParser->path[TG_USER_URL_POS].len <= 0) { return false; } - tstrncpy(pContext->user, pParser->path[TG_USER_URL_POS].pos, TSDB_USER_LEN); + tstrncpy(pContext->user, pParser->path[TG_USER_URL_POS].pos, sizeof(pContext->user)); return true; } diff --git a/src/plugins/monitor/src/monitorMain.c b/src/plugins/monitor/src/monitorMain.c index ff9faa845c..fb9fbba80d 100644 --- a/src/plugins/monitor/src/monitorMain.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -175,7 +175,7 @@ static void dnodeBuildMonitorSql(char *sql, int32_t cmd) { ", totalConns smallint, maxConns smallint" ", accessState smallint" ") tags (acctId binary(%d))", - tsMonitorDbName, TSDB_USER_LEN + 1); + tsMonitorDbName, TSDB_USER_LEN); } else if (cmd == MONITOR_CMD_CREATE_TB_ACCT_ROOT) { snprintf(sql, SQL_LENGTH, "create table if not exists %s.acct_%s using %s.acct tags('%s')", tsMonitorDbName, "root", tsMonitorDbName, "root"); From ab7b7f42e9dbb9575d9c6ea7a78fffbf3894c775 Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 10 Jun 2020 10:24:16 +0800 Subject: [PATCH 3/6] TD-459: TSDB_PASSWORD_LEN --- src/client/src/tscSQLParser.c | 2 +- src/client/src/tscSql.c | 4 ++-- src/common/src/tglobal.c | 2 +- src/plugins/http/src/gcHandle.c | 2 +- src/plugins/http/src/httpAuth.c | 4 ++-- src/plugins/http/src/restHandle.c | 2 +- src/plugins/http/src/tgHandle.c | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 9c64786459..acaabbf17d 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -169,7 +169,7 @@ static int32_t handlePassword(SSqlCmd* pCmd, SSQLToken* pPwd) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); } - if (pPwd->n > TSDB_PASSWORD_LEN) { + if (pPwd->n >= TSDB_PASSWORD_LEN) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 5f2a8598db..a5cfa40516 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -45,11 +45,11 @@ static bool validImpl(const char* str, size_t maxsize) { } static bool validUserName(const char* user) { - return validImpl(user, TSDB_USER_LEN); + return validImpl(user, TSDB_USER_LEN - 1); } static bool validPassword(const char* passwd) { - return validImpl(passwd, TSDB_PASSWORD_LEN); + return validImpl(passwd, TSDB_PASSWORD_LEN - 1); } SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, const char *db, uint16_t port, diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 8c77f0b5f3..0cd0e48fbf 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -728,7 +728,7 @@ static void doInitGlobalConfig() { cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_NOT_PRINT; cfg.minValue = 0; cfg.maxValue = 0; - cfg.ptrLength = TSDB_PASSWORD_LEN; + cfg.ptrLength = TSDB_PASSWORD_LEN - 1; cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); diff --git a/src/plugins/http/src/gcHandle.c b/src/plugins/http/src/gcHandle.c index a99059ea34..176e16301b 100644 --- a/src/plugins/http/src/gcHandle.c +++ b/src/plugins/http/src/gcHandle.c @@ -58,7 +58,7 @@ bool gcGetUserFromUrl(HttpContext* pContext) { bool gcGetPassFromUrl(HttpContext* pContext) { HttpParser* pParser = &pContext->parser; - if (pParser->path[GC_PASS_URL_POS].len > TSDB_PASSWORD_LEN - 1 || pParser->path[GC_PASS_URL_POS].len <= 0) { + if (pParser->path[GC_PASS_URL_POS].len >= TSDB_PASSWORD_LEN || pParser->path[GC_PASS_URL_POS].len <= 0) { return false; } diff --git a/src/plugins/http/src/httpAuth.c b/src/plugins/http/src/httpAuth.c index 752c7d1d50..4738da4fb0 100644 --- a/src/plugins/http/src/httpAuth.c +++ b/src/plugins/http/src/httpAuth.c @@ -89,7 +89,7 @@ bool httpParseTaosdAuthToken(HttpContext *pContext, char *token, int len) { return false; } else { tstrncpy(pContext->user, descrypt, sizeof(pContext->user)); - tstrncpy(pContext->pass, descrypt + TSDB_USER_LEN, TSDB_PASSWORD_LEN); + tstrncpy(pContext->pass, descrypt + TSDB_USER_LEN, sizeof(pContext->pass)); httpTrace("context:%p, fd:%d, ip:%s, taosd token:%s parsed success, user:%s", pContext, pContext->fd, pContext->ipstr, token, pContext->user); @@ -102,7 +102,7 @@ bool httpParseTaosdAuthToken(HttpContext *pContext, char *token, int len) { bool httpGenTaosdAuthToken(HttpContext *pContext, char *token, int maxLen) { char buffer[TSDB_USER_LEN + TSDB_PASSWORD_LEN] = {0}; strncpy(buffer, pContext->user, sizeof(pContext->user)); - strncpy(buffer + TSDB_USER_LEN, pContext->pass, TSDB_PASSWORD_LEN); + strncpy(buffer + TSDB_USER_LEN, pContext->pass, sizeof(pContext->pass)); char *encrypt = taosDesEncode(KEY_DES_4, buffer, TSDB_USER_LEN + TSDB_PASSWORD_LEN); char *base64 = base64_encode((const unsigned char *)encrypt, TSDB_USER_LEN + TSDB_PASSWORD_LEN); diff --git a/src/plugins/http/src/restHandle.c b/src/plugins/http/src/restHandle.c index b9b096ac77..93094fa287 100644 --- a/src/plugins/http/src/restHandle.c +++ b/src/plugins/http/src/restHandle.c @@ -71,7 +71,7 @@ bool restGetUserFromUrl(HttpContext* pContext) { bool restGetPassFromUrl(HttpContext* pContext) { HttpParser* pParser = &pContext->parser; - if (pParser->path[REST_PASS_URL_POS].len > TSDB_PASSWORD_LEN - 1 || pParser->path[REST_PASS_URL_POS].len <= 0) { + if (pParser->path[REST_PASS_URL_POS].len >= TSDB_PASSWORD_LEN || pParser->path[REST_PASS_URL_POS].len <= 0) { return false; } diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index abc4acae65..b85f27d175 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -316,11 +316,11 @@ bool tgGetUserFromUrl(HttpContext *pContext) { bool tgGetPassFromUrl(HttpContext *pContext) { HttpParser *pParser = &pContext->parser; - if (pParser->path[TG_PASS_URL_POS].len > TSDB_PASSWORD_LEN - 1 || pParser->path[TG_PASS_URL_POS].len <= 0) { + if (pParser->path[TG_PASS_URL_POS].len >= TSDB_PASSWORD_LEN || pParser->path[TG_PASS_URL_POS].len <= 0) { return false; } - tstrncpy(pContext->pass, pParser->path[TG_PASS_URL_POS].pos, TSDB_PASSWORD_LEN); + tstrncpy(pContext->pass, pParser->path[TG_PASS_URL_POS].pos, sizeof(pContext->pass)); return true; } From 33819c0b3a218fe8c6f13b60cf5b3351ce99826f Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 10 Jun 2020 13:36:33 +0800 Subject: [PATCH 4/6] td-459: TSDB_FILENAME_LEN --- src/dnode/src/dnodeSystem.c | 2 +- src/kit/shell/src/shellDarwin.c | 2 +- src/kit/shell/src/shellLinux.c | 2 +- src/kit/shell/src/shellWindows.c | 2 +- src/kit/taosdump/taosdump.c | 4 ++-- src/util/src/tconfig.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dnode/src/dnodeSystem.c b/src/dnode/src/dnodeSystem.c index 3efa1c728d..2fa738e480 100644 --- a/src/dnode/src/dnodeSystem.c +++ b/src/dnode/src/dnodeSystem.c @@ -29,7 +29,7 @@ int32_t main(int32_t argc, char *argv[]) { for (int32_t i = 1; i < argc; ++i) { if (strcmp(argv[i], "-c") == 0) { if (i < argc - 1) { - if (strlen(argv[++i]) > TSDB_FILENAME_LEN - 1) { + if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) { printf("config file path overflow"); exit(EXIT_FAILURE); } diff --git a/src/kit/shell/src/shellDarwin.c b/src/kit/shell/src/shellDarwin.c index 439ca6edad..1a75a2aa85 100644 --- a/src/kit/shell/src/shellDarwin.c +++ b/src/kit/shell/src/shellDarwin.c @@ -97,7 +97,7 @@ void shellParseArgument(int argc, char *argv[], struct arguments *arguments) { } } else if (strcmp(argv[i], "-c") == 0) { if (i < argc - 1) { - if (strlen(argv[++i]) > TSDB_FILENAME_LEN - 1) { + if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) { fprintf(stderr, "config file path: %s overflow max len %d\n", argv[i], TSDB_FILENAME_LEN - 1); exit(EXIT_FAILURE); } diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index 7d035126c0..829ceb9e5f 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -81,7 +81,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { fprintf(stderr, "Invalid path %s\n", arg); return -1; } - if (strlen(full_path.we_wordv[0]) > TSDB_FILENAME_LEN - 1) { + if (strlen(full_path.we_wordv[0]) >= TSDB_FILENAME_LEN) { fprintf(stderr, "config file path: %s overflow max len %d\n", full_path.we_wordv[0], TSDB_FILENAME_LEN - 1); wordfree(&full_path); return -1; diff --git a/src/kit/shell/src/shellWindows.c b/src/kit/shell/src/shellWindows.c index cf96bce5a8..8a7996d682 100644 --- a/src/kit/shell/src/shellWindows.c +++ b/src/kit/shell/src/shellWindows.c @@ -77,7 +77,7 @@ void shellParseArgument(int argc, char *argv[], struct arguments *arguments) { } } else if (strcmp(argv[i], "-c") == 0) { if (i < argc - 1) { - if (strlen(argv[++i]) > TSDB_FILENAME_LEN - 1) { + if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) { fprintf(stderr, "config file path: %s overflow max len %d\n", argv[i], TSDB_FILENAME_LEN - 1); exit(EXIT_FAILURE); } diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 6cb57ef0d5..ee792c5116 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -177,8 +177,8 @@ typedef struct SDumpArguments { char *password; uint16_t port; // output file - char output[TSDB_FILENAME_LEN + 1]; - char input[TSDB_FILENAME_LEN + 1]; + char output[TSDB_FILENAME_LEN]; + char input[TSDB_FILENAME_LEN]; char *encode; // dump unit option bool all_databases; diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index 203a34fd15..543a84dc44 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -242,7 +242,7 @@ void taosReadGlobalLogCfg() { wordexp_t full_path; wordexp(configDir, &full_path, 0); if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { - if (strlen(full_path.we_wordv[0]) > TSDB_FILENAME_LEN - 1) { + if (strlen(full_path.we_wordv[0]) >= TSDB_FILENAME_LEN) { printf("\nconfig file: %s path overflow max len %d, all variables are set to default\n", full_path.we_wordv[0], TSDB_FILENAME_LEN - 1); wordfree(&full_path); return; From 18bbbb319f5d11f67063191cc0596b0c25a01420 Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 10 Jun 2020 17:55:08 +0800 Subject: [PATCH 5/6] td-459: TSDB_TABLE_ID_LEN --- src/client/src/tscSQLParser.c | 12 ++++----- src/client/src/tscServer.c | 4 +-- .../python/linux/python2/taos/cinterface.py | 6 ++--- .../python/windows/python2/taos/cinterface.py | 6 ++--- .../python/windows/python3/taos/cinterface.py | 6 ++--- src/inc/taosdef.h | 11 ++++---- src/inc/taosmsg.h | 26 +++++++++---------- src/mnode/src/mnodeTable.c | 12 ++++----- src/plugins/http/src/httpAuth.c | 9 ++++--- src/plugins/monitor/src/monitorMain.c | 2 +- 10 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index acaabbf17d..b20676a053 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1056,12 +1056,12 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL totalLen += 1; /* here we only check the table name length limitation */ - if (tableName->n > TSDB_TABLE_NAME_LEN) { + if (tableName->n >= TSDB_TABLE_NAME_LEN) { return TSDB_CODE_TSC_INVALID_SQL; } } 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 - 1) + (TSDB_DB_NAME_LEN - 1) + sizeof(TS_PATH_DELIMITER)) { + if (tableName->n >= TSDB_TABLE_NAME_LEN + TSDB_DB_NAME_LEN) { return TSDB_CODE_TSC_INVALID_SQL; } } @@ -1078,7 +1078,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL fullName[totalLen] = 0; } - return (totalLen <= TSDB_TABLE_ID_LEN) ? TSDB_CODE_SUCCESS : TSDB_CODE_TSC_INVALID_SQL; + return (totalLen < TSDB_TABLE_ID_LEN) ? TSDB_CODE_SUCCESS : TSDB_CODE_TSC_INVALID_SQL; } static void extractColumnNameFromString(tSQLExprItem* pItem) { @@ -2052,7 +2052,7 @@ int32_t getTableIndexImpl(SSQLToken* pTableToken, SQueryInfo* pQueryInfo, SColum } pIndex->tableIndex = COLUMN_INDEX_INITIAL_VAL; - char tableName[TSDB_TABLE_ID_LEN + 1] = {0}; + char tableName[TSDB_TABLE_ID_LEN] = {0}; for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i); @@ -3616,7 +3616,7 @@ static int32_t setTableCondForSTableQuery(SQueryInfo* pQueryInfo, const char* ac taosStringBuilderAppendStringLen(&sb1, TBNAME_LIST_SEP, 1); } - char idBuf[TSDB_TABLE_ID_LEN + 1] = {0}; + char idBuf[TSDB_TABLE_ID_LEN] = {0}; int32_t xlen = strlen(segments[i]); SSQLToken t = {.z = segments[i], .n = xlen, .type = TK_STRING}; @@ -5603,7 +5603,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { } // get meter meta from mnode - strncpy(pCreateTable->usingInfo.tagdata.name, pStableMeterMetaInfo->name, TSDB_TABLE_ID_LEN); + tstrncpy(pCreateTable->usingInfo.tagdata.name, pStableMeterMetaInfo->name, sizeof(pCreateTable->usingInfo.tagdata.name)); tVariantList* pList = pInfo->pCreateTableInfo->usingInfo.pTagVals; int32_t code = tscGetTableMeta(pSql, pStableMeterMetaInfo); diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 33ab93d113..3fb22f7f8d 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1705,8 +1705,8 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) { for(int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, i); - strncpy(pMsg, pTableMetaInfo->name, TSDB_TABLE_ID_LEN); - pMsg += TSDB_TABLE_ID_LEN; + tstrncpy(pMsg, pTableMetaInfo->name, sizeof(pTableMetaInfo->name)); + pMsg += sizeof(pTableMetaInfo->name); } pCmd->msgType = TSDB_MSG_TYPE_CM_STABLE_VGROUP; diff --git a/src/connector/python/linux/python2/taos/cinterface.py b/src/connector/python/linux/python2/taos/cinterface.py index 10df10b31f..c26e5c0967 100644 --- a/src/connector/python/linux/python2/taos/cinterface.py +++ b/src/connector/python/linux/python2/taos/cinterface.py @@ -130,9 +130,9 @@ _CONVERT_FUNC = { # Corresponding TAOS_FIELD structure in C class TaosField(ctypes.Structure): - _fields_ = [('name', ctypes.c_char * 64), - ('bytes', ctypes.c_short), - ('type', ctypes.c_char)] + _fields_ = [('name', ctypes.c_char * 65), + ('type', ctypes.c_char), + ('bytes', ctypes.c_short)] # C interface class class CTaosInterface(object): diff --git a/src/connector/python/windows/python2/taos/cinterface.py b/src/connector/python/windows/python2/taos/cinterface.py index 06ade4fc35..6a9c5bfcef 100644 --- a/src/connector/python/windows/python2/taos/cinterface.py +++ b/src/connector/python/windows/python2/taos/cinterface.py @@ -130,9 +130,9 @@ _CONVERT_FUNC = { # Corresponding TAOS_FIELD structure in C class TaosField(ctypes.Structure): - _fields_ = [('name', ctypes.c_char * 64), - ('bytes', ctypes.c_short), - ('type', ctypes.c_char)] + _fields_ = [('name', ctypes.c_char * 65), + ('type', ctypes.c_char), + ('bytes', ctypes.c_short)] # C interface class class CTaosInterface(object): diff --git a/src/connector/python/windows/python3/taos/cinterface.py b/src/connector/python/windows/python3/taos/cinterface.py index c6218fe9d4..fa7124431c 100644 --- a/src/connector/python/windows/python3/taos/cinterface.py +++ b/src/connector/python/windows/python3/taos/cinterface.py @@ -130,9 +130,9 @@ _CONVERT_FUNC = { # Corresponding TAOS_FIELD structure in C class TaosField(ctypes.Structure): - _fields_ = [('name', ctypes.c_char * 64), - ('bytes', ctypes.c_short), - ('type', ctypes.c_char)] + _fields_ = [('name', ctypes.c_char * 65), + ('type', ctypes.c_char), + ('bytes', ctypes.c_short)] # C interface class class CTaosInterface(object): diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 251e3a9e40..c0b8ba3063 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -186,14 +186,14 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_BINARY_OP_MULTIPLY 14 #define TSDB_BINARY_OP_DIVIDE 15 #define TSDB_BINARY_OP_REMAINDER 16 -#define TSDB_USERID_LEN 9 #define TS_PATH_DELIMITER_LEN 1 -#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 -#define TSDB_ACCT_LEN TSDB_UNI_LEN +// ACCOUNT is a 32 bit positive integer +// this is the length of its string representation +// including the terminator zero +#define TSDB_ACCT_LEN 11 #define TSDB_PASSWORD_LEN TSDB_UNI_LEN #define TSDB_MAX_COLUMNS 1024 @@ -202,13 +202,14 @@ 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 33 +#define TSDB_TABLE_ID_LEN (TSDB_ACCT_LEN + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN) #define TSDB_COL_NAME_LEN 65 #define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64 #define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE #define TSDB_MAX_SQL_SHOW_LEN 256 #define TSDB_MAX_ALLOWED_SQL_LEN (8*1024*1024U) // sql length should be less than 8mb -#define TSDB_MAX_BYTES_PER_ROW TSDB_MAX_COLUMNS * 64 +#define TSDB_MAX_BYTES_PER_ROW (TSDB_MAX_COLUMNS * 64) #define TSDB_MAX_TAGS_LEN 65536 #define TSDB_MAX_TAGS 128 diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 0c47fad4dc..b9384f75fc 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -243,13 +243,13 @@ typedef struct { uint64_t uid; uint64_t superTableUid; uint64_t createdTime; - char tableId[TSDB_TABLE_ID_LEN + 1]; - char superTableId[TSDB_TABLE_ID_LEN + 1]; + char tableId[TSDB_TABLE_ID_LEN]; + char superTableId[TSDB_TABLE_ID_LEN]; char data[]; } SMDCreateTableMsg; typedef struct { - char tableId[TSDB_TABLE_ID_LEN + 1]; + char tableId[TSDB_TABLE_ID_LEN]; char db[TSDB_DB_NAME_LEN]; int8_t igExists; int8_t getMeta; @@ -262,12 +262,12 @@ typedef struct { } SCMCreateTableMsg; typedef struct { - char tableId[TSDB_TABLE_ID_LEN + 1]; + char tableId[TSDB_TABLE_ID_LEN]; int8_t igNotExists; } SCMDropTableMsg; typedef struct { - char tableId[TSDB_TABLE_ID_LEN + 1]; + char tableId[TSDB_TABLE_ID_LEN]; char db[TSDB_DB_NAME_LEN]; int16_t type; /* operation type */ int16_t numOfCols; /* number of schema */ @@ -292,7 +292,7 @@ typedef struct { typedef struct { char clientVersion[TSDB_VERSION_LEN]; char msgVersion[TSDB_VERSION_LEN]; - char db[TSDB_TABLE_ID_LEN + 1]; + char db[TSDB_TABLE_ID_LEN]; } SCMConnectMsg; typedef struct { @@ -342,14 +342,14 @@ typedef struct { int32_t vgId; int32_t sid; uint64_t uid; - char tableId[TSDB_TABLE_ID_LEN + 1]; + char tableId[TSDB_TABLE_ID_LEN]; } SMDDropTableMsg; typedef struct { int32_t contLen; int32_t vgId; uint64_t uid; - char tableId[TSDB_TABLE_ID_LEN + 1]; + char tableId[TSDB_TABLE_ID_LEN]; } SMDDropSTableMsg; typedef struct { @@ -521,7 +521,7 @@ typedef struct { } SCMCreateDbMsg, SCMAlterDbMsg; typedef struct { - char db[TSDB_TABLE_ID_LEN + 1]; + char db[TSDB_TABLE_ID_LEN]; uint8_t ignoreNotExists; } SCMDropDbMsg, SCMUseDbMsg; @@ -612,7 +612,7 @@ typedef struct { } SMDCreateVnodeMsg; typedef struct { - char tableId[TSDB_TABLE_ID_LEN + 1]; + char tableId[TSDB_TABLE_ID_LEN]; int16_t createFlag; char tags[]; } SCMTableInfoMsg; @@ -639,7 +639,7 @@ typedef struct { typedef struct STableMetaMsg { int32_t contLen; - char tableId[TSDB_TABLE_ID_LEN + 1]; // table id + char tableId[TSDB_TABLE_ID_LEN]; // table id uint8_t numOfTags; uint8_t precision; uint8_t tableType; @@ -660,7 +660,7 @@ typedef struct SMultiTableMeta { typedef struct { int32_t dataLen; - char name[TSDB_TABLE_ID_LEN + 1]; + char name[TSDB_TABLE_ID_LEN]; char data[TSDB_MAX_TAGS_LEN]; } STagData; @@ -746,7 +746,7 @@ typedef struct { uint64_t uid; uint64_t stime; // stream starting time int32_t status; - char tableId[TSDB_TABLE_ID_LEN + 1]; + char tableId[TSDB_TABLE_ID_LEN]; } SMDAlterStreamMsg; typedef struct { diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index a2ddd9893f..cc747364ed 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -201,7 +201,7 @@ static int32_t mnodeChildTableActionEncode(SSdbOper *pOper) { assert(pTable != NULL && pOper->rowData != NULL); int32_t len = strlen(pTable->info.tableId); - if (len > TSDB_TABLE_ID_LEN) return TSDB_CODE_MND_INVALID_TABLE_ID; + if (len >= TSDB_TABLE_ID_LEN) return TSDB_CODE_MND_INVALID_TABLE_ID; memcpy(pOper->rowData, pTable->info.tableId, len); memset(pOper->rowData + len, 0, 1); @@ -232,7 +232,7 @@ static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) { if (pTable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; int32_t len = strlen(pOper->rowData); - if (len > TSDB_TABLE_ID_LEN) { + if (len >= TSDB_TABLE_ID_LEN) { free(pTable); return TSDB_CODE_MND_INVALID_TABLE_ID; } @@ -453,7 +453,7 @@ static int32_t mnodeSuperTableActionEncode(SSdbOper *pOper) { assert(pOper->pObj != NULL && pOper->rowData != NULL); int32_t len = strlen(pStable->info.tableId); - if (len > TSDB_TABLE_ID_LEN) len = TSDB_CODE_MND_INVALID_TABLE_ID; + if (len >= TSDB_TABLE_ID_LEN) len = TSDB_CODE_MND_INVALID_TABLE_ID; memcpy(pOper->rowData, pStable->info.tableId, len); memset(pOper->rowData + len, 0, 1); @@ -477,7 +477,7 @@ static int32_t mnodeSuperTableActionDecode(SSdbOper *pOper) { if (pStable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; int32_t len = strlen(pOper->rowData); - if (len > TSDB_TABLE_ID_LEN){ + if (len >= TSDB_TABLE_ID_LEN){ free(pStable); return TSDB_CODE_MND_INVALID_TABLE_ID; } @@ -1249,7 +1249,7 @@ static int32_t mnodeGetSuperTableMeta(SMnodeMsg *pMsg) { pMeta->numOfColumns = htons((int16_t)pTable->numOfColumns); pMeta->tableType = pTable->info.type; pMeta->contLen = sizeof(STableMetaMsg) + mnodeSetSchemaFromSuperTable(pMeta->schema, pTable); - strncpy(pMeta->tableId, pTable->info.tableId, TSDB_TABLE_ID_LEN); + tstrncpy(pMeta->tableId, pTable->info.tableId, sizeof(pMeta->tableId)); pMeta->contLen = htons(pMeta->contLen); @@ -2032,7 +2032,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { pMultiMeta->numOfTables = 0; for (int32_t t = 0; t < pInfo->numOfTables; ++t) { - char * tableId = (char *)(pInfo->tableIds + t * TSDB_TABLE_ID_LEN + 1); + char * tableId = (char *)(pInfo->tableIds + t * TSDB_TABLE_ID_LEN); SChildTableObj *pTable = mnodeGetChildTable(tableId); if (pTable == NULL) continue; diff --git a/src/plugins/http/src/httpAuth.c b/src/plugins/http/src/httpAuth.c index 4738da4fb0..61ca5b4cc9 100644 --- a/src/plugins/http/src/httpAuth.c +++ b/src/plugins/http/src/httpAuth.c @@ -100,14 +100,15 @@ bool httpParseTaosdAuthToken(HttpContext *pContext, char *token, int len) { } bool httpGenTaosdAuthToken(HttpContext *pContext, char *token, int maxLen) { - char buffer[TSDB_USER_LEN + TSDB_PASSWORD_LEN] = {0}; - strncpy(buffer, pContext->user, sizeof(pContext->user)); - strncpy(buffer + TSDB_USER_LEN, pContext->pass, sizeof(pContext->pass)); + char buffer[sizeof(pContext->user) + sizeof(pContext->pass)] = {0}; + tstrncpy(buffer, pContext->user, sizeof(pContext->user)); + tstrncpy(buffer + sizeof(pContext->user), pContext->pass, sizeof(pContext->pass)); char *encrypt = taosDesEncode(KEY_DES_4, buffer, TSDB_USER_LEN + TSDB_PASSWORD_LEN); char *base64 = base64_encode((const unsigned char *)encrypt, TSDB_USER_LEN + TSDB_PASSWORD_LEN); - strncpy(token, base64, (size_t)strlen(base64)); + size_t len = strlen(base64); + tstrncpy(token, base64, len + 1); free(encrypt); free(base64); diff --git a/src/plugins/monitor/src/monitorMain.c b/src/plugins/monitor/src/monitorMain.c index fb9fbba80d..735c77ae21 100644 --- a/src/plugins/monitor/src/monitorMain.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -183,7 +183,7 @@ static void dnodeBuildMonitorSql(char *sql, int32_t cmd) { snprintf(sql, SQL_LENGTH, "create table if not exists %s.slowquery(ts timestamp, username " "binary(%d), created_time timestamp, time bigint, sql binary(%d))", - tsMonitorDbName, TSDB_TABLE_ID_LEN, TSDB_SLOW_QUERY_SQL_LEN); + tsMonitorDbName, TSDB_TABLE_ID_LEN - 1, TSDB_SLOW_QUERY_SQL_LEN); } else if (cmd == MONITOR_CMD_CREATE_TB_LOG) { snprintf(sql, SQL_LENGTH, "create table if not exists %s.log(ts timestamp, level tinyint, " From 943cdd5527aa5cad6ea7a995743f404358f3c870 Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Thu, 11 Jun 2020 11:05:20 +0800 Subject: [PATCH 6/6] TD-459: TSDB_KEY_LEN other changes: max row length from 65536 to 65535 fix byte order issue in get super table meta --- src/common/inc/tdataformat.h | 14 +++++++------- src/inc/taosdef.h | 4 ++-- src/inc/taosmsg.h | 4 ++-- src/mnode/inc/mnodeDef.h | 2 +- src/mnode/src/mnodeTable.c | 2 +- tests/pytest/table/boundary.py | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index 0e57c7317e..ea0eb9ff29 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -69,8 +69,8 @@ typedef struct { int version; // version int numOfCols; // Number of columns appended int tlen; // maximum length of a SDataRow without the header part - int16_t flen; // First part length in a SDataRow after the header part - int16_t vlen; // pure value part length, excluded the overhead + uint16_t flen; // First part length in a SDataRow after the header part + uint16_t vlen; // pure value part length, excluded the overhead STColumn columns[]; } STSchema; @@ -107,8 +107,8 @@ typedef struct { int tCols; int nCols; int tlen; - int16_t flen; - int16_t vlen; + uint16_t flen; + uint16_t vlen; int version; STColumn *columns; } STSchemaBuilder; @@ -125,16 +125,16 @@ STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder); * |<--------------------+--------------------------- len ---------------------------------->| * |<-- Head -->|<--------- flen -------------->| | * +---------------------+---------------------------------+---------------------------------+ - * | int16_t | int16_t | | | + * | uint16_t | int16_t | | | * +----------+----------+---------------------------------+---------------------------------+ * | len | sversion | First part | Second part | * +----------+----------+---------------------------------+---------------------------------+ */ typedef void *SDataRow; -#define TD_DATA_ROW_HEAD_SIZE sizeof(int16_t)*2 +#define TD_DATA_ROW_HEAD_SIZE (sizeof(uint16_t) + sizeof(int16_t)) -#define dataRowLen(r) (*(int16_t *)(r)) +#define dataRowLen(r) (*(uint16_t *)(r)) #define dataRowVersion(r) *(int16_t *)POINTER_SHIFT(r, sizeof(int16_t)) #define dataRowTuple(r) POINTER_SHIFT(r, TD_DATA_ROW_HEAD_SIZE) #define dataRowKey(r) (*(TSKEY *)(dataRowTuple(r))) diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index c0b8ba3063..e85b7f89b3 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -209,8 +209,8 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_MAX_SQL_SHOW_LEN 256 #define TSDB_MAX_ALLOWED_SQL_LEN (8*1024*1024U) // sql length should be less than 8mb -#define TSDB_MAX_BYTES_PER_ROW (TSDB_MAX_COLUMNS * 64) -#define TSDB_MAX_TAGS_LEN 65536 +#define TSDB_MAX_BYTES_PER_ROW 65535 +#define TSDB_MAX_TAGS_LEN 65535 #define TSDB_MAX_TAGS 128 #define TSDB_AUTH_LEN 16 diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index b9384f75fc..b81bc72652 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -753,8 +753,8 @@ typedef struct { char user[TSDB_USER_LEN]; char spi; char encrypt; - char secret[TSDB_KEY_LEN + 1]; - char ckey[TSDB_KEY_LEN + 1]; + char secret[TSDB_KEY_LEN]; + char ckey[TSDB_KEY_LEN]; } SDMAuthMsg, SDMAuthRsp; #pragma pack(pop) diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index c60c221bcc..51785ea61e 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -204,7 +204,7 @@ typedef struct { typedef struct SAcctObj { char user[TSDB_USER_LEN]; - char pass[TSDB_KEY_LEN + 1]; + char pass[TSDB_KEY_LEN]; SAcctCfg cfg; int32_t acctId; int64_t createdTime; diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index cc747364ed..be8e1910bc 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -1251,10 +1251,10 @@ static int32_t mnodeGetSuperTableMeta(SMnodeMsg *pMsg) { pMeta->contLen = sizeof(STableMetaMsg) + mnodeSetSchemaFromSuperTable(pMeta->schema, pTable); tstrncpy(pMeta->tableId, pTable->info.tableId, sizeof(pMeta->tableId)); + pMsg->rpcRsp.len = pMeta->contLen; pMeta->contLen = htons(pMeta->contLen); pMsg->rpcRsp.rsp = pMeta; - pMsg->rpcRsp.len = pMeta->contLen; mTrace("stable:%s, uid:%" PRIu64 " table meta is retrieved", pTable->info.tableId, pTable->uid); return TSDB_CODE_SUCCESS; diff --git a/tests/pytest/table/boundary.py b/tests/pytest/table/boundary.py index d9f0490ed4..50586b72ff 100644 --- a/tests/pytest/table/boundary.py +++ b/tests/pytest/table/boundary.py @@ -141,7 +141,7 @@ class TDTestCase: tdSql.prepare() # 8 bytes for timestamp - maxRowSize = 65536 - 8 + maxRowSize = 65535 - 8 maxCols = self.getLimitFromSourceCode('TSDB_MAX_COLUMNS') - 1 # for binary cols, 2 bytes are used for length