Commit 0d23bfd3 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

ntdll: Check output buffer before server_write_file call.

parent a240bfcf
......@@ -1227,16 +1227,13 @@ NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
status = server_get_unix_fd( hFile, FILE_WRITE_DATA, &unix_handle,
&needs_close, &type, &options );
if (status == STATUS_BAD_DEVICE_TYPE)
return server_write_file( hFile, hEvent, apc, apc_user, io_status, buffer, length, offset, key );
if (status == STATUS_ACCESS_DENIED)
{
status = server_get_unix_fd( hFile, FILE_APPEND_DATA, &unix_handle,
&needs_close, &type, &options );
append_write = TRUE;
}
if (status) return status;
if (status && status != STATUS_BAD_DEVICE_TYPE) return status;
if (!virtual_check_buffer_for_read( buffer, length ))
{
......@@ -1244,6 +1241,9 @@ NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
goto done;
}
if (status == STATUS_BAD_DEVICE_TYPE)
return server_write_file( hFile, hEvent, apc, apc_user, io_status, buffer, length, offset, key );
async_write = !(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT));
if (type == FD_TYPE_FILE)
......
......@@ -3484,6 +3484,14 @@ static void test_read_write(void)
ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
ok(iob.Information == -1, "expected -1, got %lu\n", iob.Information);
U(iob).Status = -1;
iob.Information = -1;
offset.QuadPart = 0;
status = pNtWriteFile(INVALID_HANDLE_VALUE, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
ok(status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE, "expected STATUS_OBJECT_TYPE_MISMATCH, got %#x\n", status);
ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
ok(iob.Information == -1, "expected -1, got %lu\n", iob.Information);
hfile = create_temp_file(0);
if (!hfile) return;
......@@ -3496,6 +3504,15 @@ static void test_read_write(void)
U(iob).Status = -1;
iob.Information = -1;
SetEvent(event);
status = pNtWriteFile(hfile, event, NULL, NULL, &iob, NULL, sizeof(contents), NULL, NULL);
ok(status == STATUS_INVALID_USER_BUFFER, "expected STATUS_INVALID_USER_BUFFER, got %#x\n", status);
ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
ok(iob.Information == -1, "expected -1, got %lu\n", iob.Information);
ok(!is_signaled(event), "event is not signaled\n");
U(iob).Status = -1;
iob.Information = -1;
status = pNtReadFile(hfile, 0, NULL, NULL, &iob, NULL, sizeof(contents), NULL, NULL);
ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %#x\n", status);
ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment