Skip to content

Commit

Permalink
remove customserver/customclient package length limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanshudong committed Aug 10, 2023
1 parent a6fb218 commit 24bbc52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
15 changes: 8 additions & 7 deletions examples/CustomDemo/CustomClient/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ static TC_NetWorkBuffer::PACKET_TYPE customResponse(TC_NetWorkBuffer &in, Respon

iHeaderLen = ntohl(iHeaderLen);

if (iHeaderLen > 100000 || iHeaderLen < (int)sizeof(unsigned int))
{
throw TarsDecodeException("packet length too long or too short,len:" + TC_Common::tostr(iHeaderLen));
}

// if (iHeaderLen > 100000 || iHeaderLen < (int)sizeof(unsigned int))
// {
// throw TarsDecodeException("packet length too long or too short,len:" + TC_Common::tostr(iHeaderLen));
// }
//
if (in.getBufferLength() < (uint32_t)iHeaderLen)
{
return TC_NetWorkBuffer::PACKET_LESS;
Expand Down Expand Up @@ -77,11 +77,12 @@ static shared_ptr<TC_NetWorkBuffer::Buffer> customRequest(RequestPacket& request
{
shared_ptr<TC_NetWorkBuffer::Buffer> buff = std::make_shared<TC_NetWorkBuffer::Buffer>();

unsigned int net_bufflength = htonl(request.sBuffer.size()+8);
int32_t len = request.sBuffer.size()+8;
unsigned int net_bufflength = htonl(len);
unsigned char * bufflengthptr = (unsigned char*)(&net_bufflength);

vector<char> buffer;
buffer.resize(request.sBuffer.size()+8);
buffer.resize(len);

memcpy(buffer.data(), bufflengthptr, sizeof(unsigned int));

Expand Down
9 changes: 5 additions & 4 deletions examples/CustomDemo/CustomServer/CustomServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CustomServer g_app;

static TC_NetWorkBuffer::PACKET_TYPE parse(TC_NetWorkBuffer &in, vector<char> &out)
{
LOG_CONSOLE_DEBUG << "buff len:" << in.getBufferLength() << endl;
size_t len = sizeof(tars::Int32);

if (in.getBufferLength() < len)
Expand All @@ -27,10 +28,10 @@ static TC_NetWorkBuffer::PACKET_TYPE parse(TC_NetWorkBuffer &in, vector<char> &o

iHeaderLen = ntohl(iHeaderLen);

if (iHeaderLen > 100000 || iHeaderLen < (int)sizeof(unsigned int))
{
throw TarsDecodeException("packet length too long or too short,len:" + TC_Common::tostr(iHeaderLen));
}
// if (iHeaderLen > 1000000 || iHeaderLen < (int)sizeof(unsigned int))
// {
// throw TarsDecodeException("packet length too long or too short,len:" + TC_Common::tostr(iHeaderLen));
// }

if (in.getBufferLength() < (uint32_t)iHeaderLen)
{
Expand Down

0 comments on commit 24bbc52

Please sign in to comment.