From ee28e0107cdacf85833d4b250ca6f7a29286ceb7 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Sat, 20 Oct 2018 19:18:06 +0200 Subject: [PATCH] server: Return STATUS_BUFFER_OVERFLOW in pipe_end_peek for partial reads in message mode. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/kernel32/sync.c | 1 + dlls/ntdll/tests/pipe.c | 22 ++++++++++++++++++++-- server/named_pipe.c | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/dlls/kernel32/sync.c b/dlls/kernel32/sync.c index b05cfdac04e..fe70565d0ac 100644 --- a/dlls/kernel32/sync.c +++ b/dlls/kernel32/sync.c @@ -1531,6 +1531,7 @@ BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer, status = NtFsControlFile( hPipe, 0, NULL, NULL, &io, FSCTL_PIPE_PEEK, NULL, 0, buffer, FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER, Data[cbBuffer] ) ); + if (status == STATUS_BUFFER_OVERFLOW) status = STATUS_SUCCESS; if (!status) { ULONG read_size = io.Information - FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER, Data ); diff --git a/dlls/ntdll/tests/pipe.c b/dlls/ntdll/tests/pipe.c index e04672b55e7..51024a2921b 100644 --- a/dlls/ntdll/tests/pipe.c +++ b/dlls/ntdll/tests/pipe.c @@ -927,6 +927,24 @@ static void read_pipe_test(ULONG pipe_flags, ULONG pipe_type) ResetEvent( event ); ret = WriteFile( write, buffer, 2, &written, NULL ); ok(ret && written == 2, "WriteFile error %d\n", GetLastError()); + + memset( &iosb, 0xcc, sizeof(iosb) ); + status = NtFsControlFile( read, NULL, NULL, NULL, &iosb, FSCTL_PIPE_PEEK, NULL, 0, buffer, + FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[1]) ); + if (pipe_type & PIPE_TYPE_MESSAGE) + { + ok( status == STATUS_BUFFER_OVERFLOW || status == STATUS_PENDING, + "FSCTL_PIPE_PEEK returned %x\n", status ); + ok( U(iosb).Status == STATUS_BUFFER_OVERFLOW, "wrong status %x\n", U(iosb).Status ); + } + else + { + ok( !status || status == STATUS_PENDING, "FSCTL_PIPE_PEEK returned %x\n", status ); + ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status ); + } + ok( iosb.Information == FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[1]), + "wrong info %lu\n", iosb.Information ); + status = NtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL ); if (pipe_type & PIPE_READMODE_MESSAGE) { @@ -1330,7 +1348,7 @@ static void test_pipe_state(HANDLE pipe, BOOL is_server, DWORD state) expected_status = STATUS_PIPE_BROKEN; break; } - todo_wine_if(expected_status == STATUS_BUFFER_OVERFLOW || expected_status == STATUS_PIPE_DISCONNECTED) + todo_wine_if(expected_status == STATUS_PIPE_DISCONNECTED) ok(status == expected_status, "status = %x, expected %x in %s state %u\n", status, expected_status, is_server ? "server" : "client", state); if (!status) @@ -1454,7 +1472,7 @@ static void test_pipe_with_data_state(HANDLE pipe, BOOL is_server, DWORD state) expected_status = STATUS_BUFFER_OVERFLOW; break; } - todo_wine_if(expected_status == STATUS_BUFFER_OVERFLOW || expected_status == STATUS_PIPE_DISCONNECTED) + todo_wine_if(expected_status == STATUS_PIPE_DISCONNECTED) ok(status == expected_status, "status = %x, expected %x in %s state %u\n", status, expected_status, is_server ? "server" : "client", state); if (status == STATUS_BUFFER_OVERFLOW) diff --git a/server/named_pipe.c b/server/named_pipe.c index 3e0da4f7e16..0d98bf8db2b 100644 --- a/server/named_pipe.c +++ b/server/named_pipe.c @@ -921,6 +921,7 @@ static int pipe_end_peek( struct pipe_end *pipe_end ) if (write_pos == reply_size) break; } } + if (message_length > reply_size) set_error( STATUS_BUFFER_OVERFLOW ); return 1; }