[+] AuIRPCRequest::EmptyRequest()
[*] De boog numero 2 > Constrain dispatch bytebuffer views to the exact frame length
This commit is contained in:
parent
c4df7fc4c2
commit
14ebab9d22
@ -100,6 +100,7 @@ struct AuIRPCRequest
|
||||
{
|
||||
virtual bool SetData(const AuByteBuffer &toRead) = 0;
|
||||
virtual bool SetData(const AuMemoryViewRead &view) = 0;
|
||||
virtual bool EmptyRequest() = 0;
|
||||
|
||||
virtual void SetCallback(AuSPtr<AuRPCRequestCallback> callback) = 0;
|
||||
};
|
||||
|
@ -70,13 +70,22 @@ bool AuRPCClientChannel::OnDataAvailable(AuByteBuffer &view)
|
||||
}
|
||||
|
||||
auto oldRead = view.readPtr;
|
||||
auto frameLength = view.Read<AuUInt32>();
|
||||
|
||||
if (view.Read<AuUInt32>() > bytesAvailable)
|
||||
if (!frameLength)
|
||||
{
|
||||
Disconnect();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (frameLength > bytesAvailable)
|
||||
{
|
||||
view.readPtr = oldRead;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto endPtr = oldRead + frameLength;
|
||||
|
||||
auto packetType = view.Read<AuUInt8>();
|
||||
|
||||
if (packetType == kResponseConnectOK)
|
||||
@ -100,10 +109,16 @@ bool AuRPCClientChannel::OnDataAvailable(AuByteBuffer &view)
|
||||
return true;
|
||||
}
|
||||
|
||||
auto oldLength = view.length;
|
||||
view.length = (oldRead - view.base) + frameLength;
|
||||
|
||||
response->message = &view;
|
||||
|
||||
response->Deserialize();
|
||||
this->ProcessResponse(response);
|
||||
|
||||
view.readPtr = endPtr;
|
||||
view.length = oldLength;
|
||||
}
|
||||
|
||||
} while (true);
|
||||
|
@ -35,6 +35,11 @@ void AuRPCRequest::SetCallback(AuSPtr<AuRPCRequestCallback> callback)
|
||||
this->callback = callback;
|
||||
}
|
||||
|
||||
bool AuRPCRequest::EmptyRequest()
|
||||
{
|
||||
return SetData(AuMemoryViewRead {});
|
||||
}
|
||||
|
||||
AuMemoryViewRead AuRPCRequest::GetData()
|
||||
{
|
||||
return this->data;
|
||||
|
@ -20,6 +20,8 @@ struct AuRPCRequest : AuIRPCRequest
|
||||
|
||||
void SetCallback(AuSPtr<AuRPCRequestCallback> callback) override;
|
||||
|
||||
bool EmptyRequest() override;
|
||||
|
||||
ERPCRequestState GetState();
|
||||
|
||||
AuMemoryViewRead GetData();
|
||||
|
@ -92,8 +92,8 @@ void AuRPCServer::Dispatch(AuRPCServerChannel *channel,
|
||||
|
||||
itr->second->Dispatch(*response, request->methodId, *buffer);
|
||||
|
||||
channel->SendResponse(response);
|
||||
response->FinalizeWrite();
|
||||
channel->SendResponse(response);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
@ -66,7 +66,14 @@ bool AuRPCServerChannel::OnDataAvailable(AuByteBuffer& view)
|
||||
|
||||
auto oldRead = view.readPtr;
|
||||
|
||||
if (view.Read<AuUInt32>() > bytesAvailable)
|
||||
auto frameLength = view.Read<AuUInt32>();
|
||||
if (!frameLength)
|
||||
{
|
||||
FatalError();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (frameLength > bytesAvailable)
|
||||
{
|
||||
view.readPtr = oldRead;
|
||||
return true;
|
||||
@ -99,7 +106,13 @@ bool AuRPCServerChannel::OnDataAvailable(AuByteBuffer& view)
|
||||
request->methodId = view.Read<AuUInt32>();
|
||||
request->cookie = view.Read<AuUInt64>();
|
||||
|
||||
auto oldLength = view.length;
|
||||
view.length = (oldRead - view.base) + frameLength;
|
||||
|
||||
this->server_->Dispatch(this, request, &view);
|
||||
|
||||
view.readPtr = frameLength + oldRead;
|
||||
view.length = oldLength;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user