From 9e5f835ac7168fa400635b2af8593fca8da63887 Mon Sep 17 00:00:00 2001 From: stephenkgu Date: Sat, 12 Dec 2020 09:19:15 +0800 Subject: [PATCH] [TD-1827]: force version check for client messages --- src/client/src/tscServer.c | 5 +++-- src/dnode/src/dnodeMRead.c | 2 -- src/dnode/src/dnodeMWrite.c | 2 -- src/dnode/src/dnodeShell.c | 13 ++++++++++++- src/dnode/src/dnodeVRead.c | 2 -- src/dnode/src/dnodeVWrite.c | 1 - src/inc/taosmsg.h | 4 ++++ 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 994dace1e3..174c9ea532 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -214,7 +214,7 @@ int tscSendMsgToServer(SSqlObj *pSql) { STscObj* pObj = pSql->pTscObj; SSqlCmd* pCmd = &pSql->cmd; - char *pMsg = rpcMallocCont(pCmd->payloadLen); + char *pMsg = rpcMallocCont(sizeof(SMsgVersion) + pCmd->payloadLen); if (NULL == pMsg) { tscError("%p msg:%s malloc failed", pSql, taosMsg[pSql->cmd.msgType]); return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -225,7 +225,8 @@ int tscSendMsgToServer(SSqlObj *pSql) { tscDumpMgmtEpSet(pSql); } - memcpy(pMsg, pSql->cmd.payload, pSql->cmd.payloadLen); + tstrncpy(pMsg, version, sizeof(SMsgVersion)); + memcpy(pMsg + sizeof(SMsgVersion), pSql->cmd.payload, pSql->cmd.payloadLen); SRpcMsg rpcMsg = { .msgType = pSql->cmd.msgType, diff --git a/src/dnode/src/dnodeMRead.c b/src/dnode/src/dnodeMRead.c index 0fc6400d99..b32326f4c2 100644 --- a/src/dnode/src/dnodeMRead.c +++ b/src/dnode/src/dnodeMRead.c @@ -124,8 +124,6 @@ void dnodeDispatchToMReadQueue(SRpcMsg *pMsg) { SMnodeMsg *pRead = mnodeCreateMsg(pMsg); taosWriteQitem(tsMReadQueue, TAOS_QTYPE_RPC, pRead); } - - rpcFreeCont(pMsg->pCont); } static void dnodeFreeMReadMsg(SMnodeMsg *pRead) { diff --git a/src/dnode/src/dnodeMWrite.c b/src/dnode/src/dnodeMWrite.c index 414b66653d..9007b54d47 100644 --- a/src/dnode/src/dnodeMWrite.c +++ b/src/dnode/src/dnodeMWrite.c @@ -125,8 +125,6 @@ void dnodeDispatchToMWriteQueue(SRpcMsg *pMsg) { taosMsg[pWrite->rpcMsg.msgType], tsMWriteQueue); taosWriteQitem(tsMWriteQueue, TAOS_QTYPE_RPC, pWrite); } - - rpcFreeCont(pMsg->pCont); } static void dnodeFreeMWriteMsg(SMnodeMsg *pWrite) { diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index 79cc70005b..8899c92db3 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -127,7 +127,18 @@ static void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { } else {} if ( dnodeProcessShellMsgFp[pMsg->msgType] ) { + SMsgVersion *pMsgVersion = pMsg->pCont; + if (taosCheckVersion(pMsgVersion->clientVersion, version, 3) != TSDB_CODE_SUCCESS) { + rpcMsg.code = TSDB_CODE_TSC_INVALID_VERSION; + rpcSendResponse(&rpcMsg); + rpcFreeCont(pMsg->pCont); + return; // todo change the error code + } + pMsg->pCont += sizeof(*pMsgVersion); + (*dnodeProcessShellMsgFp[pMsg->msgType])(pMsg); + + rpcFreeCont(pMsg->pCont - sizeof(*pMsgVersion)); } else { dError("RPC %p, shell msg:%s is not processed", pMsg->handle, taosMsg[pMsg->msgType]); rpcMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED; @@ -231,4 +242,4 @@ SStatisInfo dnodeGetStatisInfo() { } return info; -} \ No newline at end of file +} diff --git a/src/dnode/src/dnodeVRead.c b/src/dnode/src/dnodeVRead.c index 3f31e49370..2995116ef5 100644 --- a/src/dnode/src/dnodeVRead.c +++ b/src/dnode/src/dnodeVRead.c @@ -77,8 +77,6 @@ void dnodeDispatchToVReadQueue(SRpcMsg *pMsg) { SRpcMsg rpcRsp = {.handle = pMsg->handle, .code = TSDB_CODE_VND_INVALID_VGROUP_ID}; rpcSendResponse(&rpcRsp); } - - rpcFreeCont(pMsg->pCont); } void *dnodeAllocVQueryQueue(void *pVnode) { diff --git a/src/dnode/src/dnodeVWrite.c b/src/dnode/src/dnodeVWrite.c index a5ae8ac830..959789a6d2 100644 --- a/src/dnode/src/dnodeVWrite.c +++ b/src/dnode/src/dnodeVWrite.c @@ -102,7 +102,6 @@ void dnodeDispatchToVWriteQueue(SRpcMsg *pRpcMsg) { } vnodeRelease(pVnode); - rpcFreeCont(pRpcMsg->pCont); } void *dnodeAllocVWriteQueue(void *pVnode) { diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 27d857ce14..a429ba3271 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -198,6 +198,10 @@ typedef struct { int32_t numOfVnodes; } SMsgDesc; +typedef struct SMsgVersion { + char clientVersion[TSDB_VERSION_LEN]; +} SMsgVersion; + typedef struct SMsgHead { int32_t contLen; int32_t vgId; -- GitLab