diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 52240941f2f80be75afc0832e97acf8d421e5743..f550bbd000bc894a20b00a4d6195059a478c3da3 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 528c936e124a26f25c1c27fad2bea3310cf50059..9c64786459518a7d0226a7507a7e30d8318b7e0e 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 12754b164bc4e50e4f6de8c41a9a072f2ce9b434..8c77f0b5f316617d2fe7ee0f1b58617cec80a084 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 3f3c5f2796c9704b118325dc406d82674277e168..4252e63f8d288247bb980d27fcc80e20ffb484ba 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 6a0219d6fc3218218d6d9cd9db0bfd82f13c8d21..0c47fad4dc94c3e4ed106ee8f47cb479d101c80e 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 14cd4057632b1abc834a5393e4a6424dc2d1ef8d..c60c221bcc13634b2341aef02e164345e3f2fa23 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 30745db035c675004ae8b449c282c7fc26a2e172..c9f7cc8e2a94e6f33d55546ab547a5dc95db68f5 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 96bc98d6590c4effa0ae894904dcdb2f648dc69f..5b637d03bd48bc99e80208899b43f92c2bc1d8d2 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 aab0847a6b721e88ef1ab303ee76195d9d78cc66..ee79d962bad8fd86483518af6fec2dba3532d479 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 9be2796a9629055fa5fa5b77b5bdb689970542da..b8885431370999a6b11de3a2b5d5c5a6757ceba3 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 41209801233c6621c9f5a7d233c7d01718d54ba4..a99059ea34b9a307c544bc43b8469adb7fd62d97 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 ccf39642c9472a3ec971ecc2e763f7fa9d5fd72d..752c7d1d5080cfe56fff4c3b63de45aee4d56c53 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 d481a654d89e41ee296645fe32cb5fff38abf521..b9b096ac77e87a6bf7903d10e87522f3bc79c26e 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 945eff76112fa2db9ef34e7d5e1051870985bd0e..abc4acae654d66bcb93ed6e68744ffafdd9a2b51 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 ff9faa845c104d165db097595f4f7133eb313fc9..fb9fbba80db46bec3b8941c4878b023cc79817ba 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");