From 7f1232144a55faa75d7e522c0966c56a8a9a5f8c Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 10 Jun 2020 10:09:35 +0800 Subject: [PATCH] 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"); -- GitLab