Protect against invalid socket data potentially causing crashes

This commit is contained in:
baldurk
2023-08-03 14:43:53 +01:00
parent 65859d13bf
commit 9995c1f0cf
3 changed files with 13 additions and 0 deletions
+4
View File
@@ -180,6 +180,8 @@ static bool HandleHandshakeClient(ActiveClient &activeClient, ClientThread *thre
{
ReadSerialiser ser(new StreamReader(threadData->socket, Ownership::Nothing), Ownership::Stream);
ser.SetStreamingMode(true);
// this thread just handles receiving the handshake and sending a busy signal without blocking
// the server thread
RemoteServerPacket type = ser.ReadChunk<RemoteServerPacket>();
@@ -1206,6 +1208,8 @@ RENDERDOC_CreateRemoteServerConnection(const rdcstr &URL, IRemoteServer **rend)
{
ReadSerialiser ser(new StreamReader(sock, Ownership::Nothing), Ownership::Stream);
ser.SetStreamingMode(true);
RemoteServerPacket type = ser.ReadChunk<RemoteServerPacket>();
uint32_t remoteVersion = 0;
+2
View File
@@ -471,6 +471,8 @@ void RenderDoc::TargetControlServerThread(Network::Socket *sock)
{
ReadSerialiser ser(new StreamReader(client, Ownership::Nothing), Ownership::Stream);
ser.SetStreamingMode(true);
PacketType type = ser.ReadChunk<PacketType>();
if(type != ePacket_Handshake)
+7
View File
@@ -179,6 +179,13 @@ uint32_t Serialiser<SerialiserMode::Reading>::BeginChunk(uint32_t, uint64_t)
m_ChunkMetadata.length = chunkSize;
}
uint64_t len = m_ChunkMetadata.length;
VerifyArraySize(m_ChunkMetadata.length);
// if length was set to 0 by VerifyArraySize due to being invalid, set it to something
// reasonable just to prevent knock-on problems with error handling
if(len != 0 && m_ChunkMetadata.length == 0)
m_ChunkMetadata.length = 1024;
m_LastChunkOffset = m_Read->GetOffset();
}