Skip to content

Commit

Permalink
kernel32: Fix CancelIoEx return value.
Browse files Browse the repository at this point in the history
In commit 27ecc6b ("ntdll: Fix iosb handling in NtCancelIoFile()"),
NtCancelIoFile(Ex) was updated to return its status rather than
unconditionally setting it in io_status->u.Status (though the write
was retained in the success case). As a result, in the error case,
the kernelbase wrappers now interpret unitialized memory as an error
code, since io_status->u.Status is never written.

Signed-off-by: Keno Fischer <keno@juliacomputing.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
  • Loading branch information
Keno authored and julliard committed Dec 23, 2021
1 parent 65f04bc commit d96975d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 12 additions & 0 deletions dlls/kernel32/tests/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2941,6 +2941,7 @@ static void test_blocking_rw(HANDLE writer, HANDLE reader, DWORD buf_size, BOOL
OVERLAPPED read_overlapped, read_overlapped2, write_overlapped, write_overlapped2;
char buf[10000], read_buf[10000];
HANDLE flush_thread;
BOOL res;

memset(buf, 0xaa, sizeof(buf));

Expand Down Expand Up @@ -3074,6 +3075,17 @@ static void test_blocking_rw(HANDLE writer, HANDLE reader, DWORD buf_size, BOOL
overlapped_write_sync(writer, buf, 1);
test_overlapped_result(reader, &read_overlapped, 1, FALSE);

/* Test that canceling the same operation twice gives a sensible error */
SetLastError(0xdeadbeef);
overlapped_read_async(reader, read_buf, 1, &read_overlapped2);
res = pCancelIoEx(reader, &read_overlapped2);
ok(res, "CancelIoEx failed with error %d\n", GetLastError());
res = pCancelIoEx(reader, &read_overlapped2);
ok(!res, "CancelIOEx succeeded unexpectedly");
ok(GetLastError() == ERROR_NOT_FOUND,
"In CancelIoEx failure, expected ERROR_NOT_FOUND, got %d\n", GetLastError());
test_overlapped_failure(reader, &read_overlapped2, ERROR_OPERATION_ABORTED);

/* make two async writes, cancel the first one and make sure that we read from the second one */
overlapped_write_async(writer, buf, buf_size+2000, &write_overlapped);
overlapped_write_async(writer, buf, 1, &write_overlapped2);
Expand Down
6 changes: 2 additions & 4 deletions dlls/kernelbase/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2872,8 +2872,7 @@ BOOL WINAPI DECLSPEC_HOTPATCH CancelIo( HANDLE handle )
{
IO_STATUS_BLOCK io;

NtCancelIoFile( handle, &io );
return set_ntstatus( io.u.Status );
return set_ntstatus( NtCancelIoFile( handle, &io ) );
}


Expand All @@ -2884,8 +2883,7 @@ BOOL WINAPI DECLSPEC_HOTPATCH CancelIoEx( HANDLE handle, LPOVERLAPPED overlapped
{
IO_STATUS_BLOCK io;

NtCancelIoFileEx( handle, (PIO_STATUS_BLOCK)overlapped, &io );
return set_ntstatus( io.u.Status );
return set_ntstatus( NtCancelIoFileEx( handle, (PIO_STATUS_BLOCK)overlapped, &io ) );
}


Expand Down

0 comments on commit d96975d

Please sign in to comment.