fix: check the compatibility of client version and server version
This commit is contained in:
parent
e37ca08bbc
commit
9be3e20276
|
@ -612,6 +612,7 @@ typedef struct {
|
|||
char user[TSDB_USER_LEN];
|
||||
char passwd[TSDB_PASSWORD_LEN];
|
||||
int64_t startTime;
|
||||
char sVer[TSDB_VERSION_LEN];
|
||||
} SConnectReq;
|
||||
|
||||
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_UTIL_VERSION_H_
|
||||
#define _TD_UTIL_VERSION_H_
|
||||
#ifndef _TD_UTIL_TVERSION_H_
|
||||
#define _TD_UTIL_TVERSION_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
|
@ -25,9 +25,11 @@ extern "C" {
|
|||
int32_t taosVersionStrToInt(const char *vstr, int32_t *vint);
|
||||
int32_t taosVersionIntToStr(int32_t vint, char *vstr, int32_t len);
|
||||
int32_t taosCheckVersionCompatible(int32_t clientVer, int32_t serverVer, int32_t comparedSegments);
|
||||
int32_t taosCheckVersionCompatibleFromStr(const char *pClientVersion, const char *pServerVersion,
|
||||
int32_t comparedSegments);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_UTIL_VERSION_H_*/
|
||||
#endif /*_TD_UTIL_TVERSION_H_*/
|
||||
|
|
|
@ -1307,6 +1307,7 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest) {
|
|||
tstrncpy(connectReq.app, appInfo.appName, sizeof(connectReq.app));
|
||||
tstrncpy(connectReq.user, pObj->user, sizeof(connectReq.user));
|
||||
tstrncpy(connectReq.passwd, pObj->pass, sizeof(connectReq.passwd));
|
||||
tstrncpy(connectReq.sVer, version, sizeof(connectReq.sVer));
|
||||
|
||||
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq);
|
||||
void* pReq = taosMemoryMalloc(contLen);
|
||||
|
|
|
@ -18,10 +18,12 @@
|
|||
#include "clientLog.h"
|
||||
#include "os.h"
|
||||
#include "query.h"
|
||||
#include "tdef.h"
|
||||
#include "tname.h"
|
||||
#include "tdatablock.h"
|
||||
#include "systable.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "tname.h"
|
||||
#include "tversion.h"
|
||||
|
||||
static void setErrno(SRequestObj* pRequest, int32_t code) {
|
||||
pRequest->code = code;
|
||||
|
@ -74,6 +76,12 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
goto End;
|
||||
}
|
||||
|
||||
if ((code = taosCheckVersionCompatibleFromStr(version, connectRsp.sVer, 2)) != 0) {
|
||||
setErrno(pRequest, code);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
goto End;
|
||||
}
|
||||
|
||||
int32_t now = taosGetTimestampSec();
|
||||
int32_t delta = abs(now - connectRsp.svrTimestamp);
|
||||
if (delta > timestampDeltaLimit) {
|
||||
|
@ -475,7 +483,8 @@ static int32_t buildShowVariablesRsp(SArray* pVars, SRetrieveTableRsp** pRsp) {
|
|||
blockDataDestroy(pBlock);
|
||||
|
||||
if (len != rspSize - sizeof(SRetrieveTableRsp)) {
|
||||
uError("buildShowVariablesRsp error, len:%d != rspSize - sizeof(SRetrieveTableRsp):%" PRIu64, len, (uint64_t) (rspSize - sizeof(SRetrieveTableRsp)));
|
||||
uError("buildShowVariablesRsp error, len:%d != rspSize - sizeof(SRetrieveTableRsp):%" PRIu64, len,
|
||||
(uint64_t)(rspSize - sizeof(SRetrieveTableRsp)));
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
|
|
|
@ -3741,6 +3741,7 @@ int32_t tSerializeSConnectReq(void *buf, int32_t bufLen, SConnectReq *pReq) {
|
|||
if (tEncodeCStr(&encoder, pReq->user) < 0) return -1;
|
||||
if (tEncodeCStrWithLen(&encoder, pReq->passwd, TSDB_PASSWORD_LEN) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->startTime) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->sVer) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
|
@ -3760,6 +3761,12 @@ int32_t tDeserializeSConnectReq(void *buf, int32_t bufLen, SConnectReq *pReq) {
|
|||
if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->passwd) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->startTime) < 0) return -1;
|
||||
// Check the client version from version 3.0.3.0
|
||||
if (tDecodeIsEnd(&decoder)) {
|
||||
tDecoderClear(&decoder);
|
||||
return TSDB_CODE_VERSION_NOT_COMPATIBLE;
|
||||
}
|
||||
if (tDecodeCStrTo(&decoder, pReq->sVer) < 0) return -1;
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "mndStb.h"
|
||||
#include "mndUser.h"
|
||||
#include "tglobal.h"
|
||||
#include "version.h"
|
||||
#include "tversion.h"
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
|
@ -221,8 +221,13 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
|||
char ip[24] = {0};
|
||||
const STraceId *trace = &pReq->info.traceId;
|
||||
|
||||
if (tDeserializeSConnectReq(pReq->pCont, pReq->contLen, &connReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
if ((code = tDeserializeSConnectReq(pReq->pCont, pReq->contLen, &connReq)) != 0) {
|
||||
terrno = (-1 == code ? TSDB_CODE_INVALID_MSG : code);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if ((code = taosCheckVersionCompatibleFromStr(connReq.sVer, version, 2)) != 0) {
|
||||
terrno = code;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
|
|
@ -89,3 +89,20 @@ int32_t taosCheckVersionCompatible(int32_t clientVer, int32_t serverVer, int32_t
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t taosCheckVersionCompatibleFromStr(const char *pClientVersion, const char *pServerVersion,
|
||||
int32_t comparedSegments) {
|
||||
int32_t clientVersion = 0;
|
||||
int32_t serverVersion = 0;
|
||||
int32_t code = taosVersionStrToInt(pClientVersion, &clientVersion);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = taosVersionStrToInt(pServerVersion, &serverVersion);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = taosCheckVersionCompatible(clientVersion, serverVersion, comparedSegments);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
code = terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
Loading…
Reference in New Issue