From ea7178d714541cc9190dd416fa664793d64968a2 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 18 Sep 2024 10:46:42 +0800 Subject: [PATCH] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/inc/transComm.h | 2 +- source/libs/transport/src/transCli.c | 2 +- source/libs/transport/src/transComm.c | 8 +++++--- source/libs/transport/src/transSvr.c | 11 ++++++----- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index ea79e3582f..c8ce8e5f45 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -461,7 +461,7 @@ void transPrintEpSet(SEpSet* pEpSet); void transFreeMsg(void* msg); int32_t transCompressMsg(char* msg, int32_t len); -int32_t transDecompressMsg(char** msg, int32_t len); +int32_t transDecompressMsg(char** msg, int32_t* len); int32_t transOpenRefMgt(int size, void (*func)(void*)); void transCloseRefMgt(int32_t refMgt); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index e7fb1893cf..e2f214a564 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -561,7 +561,7 @@ void cliHandleResp(SCliConn* conn) { return; } - if ((code = transDecompressMsg((char**)&pHead, msgLen)) < 0) { + if ((code = transDecompressMsg((char**)&pHead, &msgLen)) < 0) { tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); // TODO: notify cb return; diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 060ab2edae..eb045f8e8a 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -59,7 +59,7 @@ int32_t transCompressMsg(char* msg, int32_t len) { taosMemoryFree(buf); return ret; } -int32_t transDecompressMsg(char** msg, int32_t len) { +int32_t transDecompressMsg(char** msg, int32_t* len) { STransMsgHead* pHead = (STransMsgHead*)(*msg); if (pHead->comp == 0) return 0; @@ -68,16 +68,18 @@ int32_t transDecompressMsg(char** msg, int32_t len) { STransCompMsg* pComp = (STransCompMsg*)pCont; int32_t oriLen = htonl(pComp->contLen); - char* buf = taosMemoryCalloc(1, oriLen + sizeof(STransMsgHead)); + int32_t tlen = *len; + char* buf = taosMemoryCalloc(1, oriLen + sizeof(STransMsgHead)); if (buf == NULL) { return terrno; } STransMsgHead* pNewHead = (STransMsgHead*)buf; int32_t decompLen = LZ4_decompress_safe(pCont + sizeof(STransCompMsg), (char*)pNewHead->content, - len - sizeof(STransMsgHead) - sizeof(STransCompMsg), oriLen); + tlen - sizeof(STransMsgHead) - sizeof(STransCompMsg), oriLen); memcpy((char*)pNewHead, (char*)pHead, sizeof(STransMsgHead)); + *len = oriLen + sizeof(STransMsgHead); pNewHead->msgLen = htonl(oriLen + sizeof(STransMsgHead)); taosMemoryFree(pHead); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index bdfa024026..7e86ef546f 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -510,6 +510,12 @@ static bool uvHandleReq(SSvrConn* pConn) { tError("%s conn %p read invalid packet", transLabel(pInst), pConn); return false; } + if (transDecompressMsg((char**)&pHead, &msgLen) < 0) { + tError("%s conn %p recv invalid packet, failed to decompress", transLabel(pInst), pConn); + taosMemoryFree(pHead); + return false; + } + if (uvConnMayGetUserInfo(pConn, &pHead, &msgLen) == true) { tDebug("%s conn %p get user info", transLabel(pInst), pConn); } @@ -518,11 +524,6 @@ static bool uvHandleReq(SSvrConn* pConn) { tTrace("%s conn %p not reset read buf", transLabel(pInst), pConn); } - if (transDecompressMsg((char**)&pHead, msgLen) < 0) { - tError("%s conn %p recv invalid packet, failed to decompress", transLabel(pInst), pConn); - taosMemoryFree(pHead); - return false; - } pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen);