rpcrt4: Make RPCRT4_Receive more compatible with read(2).
This commit is contained in:
parent
d571441562
commit
9a4abffa18
|
@ -289,6 +289,21 @@ RPC_STATUS RPCRT4_Send(RpcConnection *Connection, RpcPktHdr *Header,
|
||||||
return RPC_S_OK;
|
return RPC_S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* rpcrt4_conn_read (internal)
|
||||||
|
*
|
||||||
|
* Reads data from a connection
|
||||||
|
*/
|
||||||
|
static int rpcrt4_conn_read(RpcConnection *Connection,
|
||||||
|
void *buffer, unsigned int count)
|
||||||
|
{
|
||||||
|
DWORD dwRead = 0;
|
||||||
|
if (!ReadFile(Connection->conn, buffer, count, &dwRead, NULL) &&
|
||||||
|
(GetLastError() != ERROR_MORE_DATA))
|
||||||
|
return -1;
|
||||||
|
return dwRead;
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* RPCRT4_Receive (internal)
|
* RPCRT4_Receive (internal)
|
||||||
*
|
*
|
||||||
|
@ -298,7 +313,8 @@ RPC_STATUS RPCRT4_Receive(RpcConnection *Connection, RpcPktHdr **Header,
|
||||||
PRPC_MESSAGE pMsg)
|
PRPC_MESSAGE pMsg)
|
||||||
{
|
{
|
||||||
RPC_STATUS status;
|
RPC_STATUS status;
|
||||||
DWORD dwRead, hdr_length;
|
DWORD hdr_length;
|
||||||
|
LONG dwRead;
|
||||||
unsigned short first_flag;
|
unsigned short first_flag;
|
||||||
unsigned long data_length;
|
unsigned long data_length;
|
||||||
unsigned long buffer_length;
|
unsigned long buffer_length;
|
||||||
|
@ -310,13 +326,7 @@ RPC_STATUS RPCRT4_Receive(RpcConnection *Connection, RpcPktHdr **Header,
|
||||||
TRACE("(%p, %p, %p)\n", Connection, Header, pMsg);
|
TRACE("(%p, %p, %p)\n", Connection, Header, pMsg);
|
||||||
|
|
||||||
/* read packet common header */
|
/* read packet common header */
|
||||||
if (!ReadFile(Connection->conn, &common_hdr, sizeof(common_hdr), &dwRead, NULL)) {
|
dwRead = rpcrt4_conn_read(Connection, &common_hdr, sizeof(common_hdr));
|
||||||
if (GetLastError() != ERROR_MORE_DATA) {
|
|
||||||
WARN("ReadFile failed with error %ld\n", GetLastError());
|
|
||||||
status = RPC_S_PROTOCOL_ERROR;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dwRead != sizeof(common_hdr)) {
|
if (dwRead != sizeof(common_hdr)) {
|
||||||
WARN("Short read of header, %ld/%d bytes\n", dwRead, sizeof(common_hdr));
|
WARN("Short read of header, %ld/%d bytes\n", dwRead, sizeof(common_hdr));
|
||||||
status = RPC_S_PROTOCOL_ERROR;
|
status = RPC_S_PROTOCOL_ERROR;
|
||||||
|
@ -342,14 +352,7 @@ RPC_STATUS RPCRT4_Receive(RpcConnection *Connection, RpcPktHdr **Header,
|
||||||
memcpy(*Header, &common_hdr, sizeof(common_hdr));
|
memcpy(*Header, &common_hdr, sizeof(common_hdr));
|
||||||
|
|
||||||
/* read the rest of packet header */
|
/* read the rest of packet header */
|
||||||
if (!ReadFile(Connection->conn, &(*Header)->common + 1,
|
dwRead = rpcrt4_conn_read(Connection, &(*Header)->common + 1, hdr_length - sizeof(common_hdr));
|
||||||
hdr_length - sizeof(common_hdr), &dwRead, NULL)) {
|
|
||||||
if (GetLastError() != ERROR_MORE_DATA) {
|
|
||||||
WARN("ReadFile failed with error %ld\n", GetLastError());
|
|
||||||
status = RPC_S_PROTOCOL_ERROR;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dwRead != hdr_length - sizeof(common_hdr)) {
|
if (dwRead != hdr_length - sizeof(common_hdr)) {
|
||||||
WARN("bad header length, %ld/%ld bytes\n", dwRead, hdr_length - sizeof(common_hdr));
|
WARN("bad header length, %ld/%ld bytes\n", dwRead, hdr_length - sizeof(common_hdr));
|
||||||
status = RPC_S_PROTOCOL_ERROR;
|
status = RPC_S_PROTOCOL_ERROR;
|
||||||
|
@ -387,13 +390,7 @@ RPC_STATUS RPCRT4_Receive(RpcConnection *Connection, RpcPktHdr **Header,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data_length == 0) dwRead = 0; else
|
if (data_length == 0) dwRead = 0; else
|
||||||
if (!ReadFile(Connection->conn, buffer_ptr, data_length, &dwRead, NULL)) {
|
dwRead = rpcrt4_conn_read(Connection, buffer_ptr, data_length);
|
||||||
if (GetLastError() != ERROR_MORE_DATA) {
|
|
||||||
WARN("ReadFile failed with error %ld\n", GetLastError());
|
|
||||||
status = RPC_S_PROTOCOL_ERROR;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dwRead != data_length) {
|
if (dwRead != data_length) {
|
||||||
WARN("bad data length, %ld/%ld\n", dwRead, data_length);
|
WARN("bad data length, %ld/%ld\n", dwRead, data_length);
|
||||||
status = RPC_S_PROTOCOL_ERROR;
|
status = RPC_S_PROTOCOL_ERROR;
|
||||||
|
@ -413,13 +410,7 @@ RPC_STATUS RPCRT4_Receive(RpcConnection *Connection, RpcPktHdr **Header,
|
||||||
TRACE("next header\n");
|
TRACE("next header\n");
|
||||||
|
|
||||||
/* read the header of next packet */
|
/* read the header of next packet */
|
||||||
if (!ReadFile(Connection->conn, *Header, hdr_length, &dwRead, NULL)) {
|
dwRead = rpcrt4_conn_read(Connection, *Header, hdr_length);
|
||||||
if (GetLastError() != ERROR_MORE_DATA) {
|
|
||||||
WARN("ReadFile failed with error %ld\n", GetLastError());
|
|
||||||
status = GetLastError();
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dwRead != hdr_length) {
|
if (dwRead != hdr_length) {
|
||||||
WARN("invalid packet header size (%ld)\n", dwRead);
|
WARN("invalid packet header size (%ld)\n", dwRead);
|
||||||
status = RPC_S_PROTOCOL_ERROR;
|
status = RPC_S_PROTOCOL_ERROR;
|
||||||
|
|
Loading…
Reference in New Issue