3.2.5.1 Processing the RDP_PRECONNECTION PDU V1 and V2

When processing either RDP_PRECONNECTION_PDU_V1 or RDP_PRECONNECTION_PDU_V2, the server MUST not make assumptions about the way the PDU is delivered by TCP/IP. The server MUST only read the bytes that are part of this PDU. The server MUST NOT read more than the minimum required size.

The server SHOULD wait and receive the whole PDU.<4> After the whole PDU is received, the server MUST determine the process for which the connection is intended. The server MUST hand over the connection to the specified process. If the information in the PDU does not map to any process, the server SHOULD disconnect the client.<5>

In order to process the PDU, the server MUST first determine how long the PDU is. The server does this by reading the 4 bytes that correspond to the cbSize field of the PDU, as specified in section 2.2.1.1. If the cbSize field is 16 bytes, the server MUST consider the PDU an RDP_PRECONNECTION_PDU_V1. If the size is greater than or equal to 18 bytes, the server MUST consider the PDU an RDP_PRECONNECTION_PDU_V2, check that the size is in the expected range based on the cbSize field, and disconnect the client if the size is not in the expected range. If the size is equal to 17 bytes or less than 16 bytes the server SHOULD<6> disconnect the client. If the Version field indicates that the PDU is RDP_PRECONNECTION_PDU_V1 and if the cbSize field is greater than 16 bytes, then the server SHOULD<7> disconnect the client.

When the cbSize field is received, the server MUST read that number of bytes from the TCP/IP stream.

When the server receives an RDP_PRECONNECTION_PDU_V2, it MUST verify that the size of the wszPCB field is consistent with the PDU size that is expected by the cbSize field. The cbSize MUST be greater than or equal to the size of the RDP_PRECONNECTION_PDU_V1, plus the size of the cchPCB field and wszPCB field, calculated as cchPCB multiplied by 2. If cbSize does not meet this condition, the server SHOULD disconnect the client.<8>

 Once the PDU is received the server MUST determine if the received PDU is of the type supported by the server. If the type is not supported by the server, the latter SHOULD<9> disconnect the client.