Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
8de57bd5
Commit
8de57bd5
authored
Jan 14, 2009
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernel32/tests: Add test cases for reading/writing from an invalid buffer address.
parent
63bff093
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
1 deletion
+91
-1
file.c
dlls/kernel32/tests/file.c
+91
-1
No files found.
dlls/kernel32/tests/file.c
View file @
8de57bd5
...
...
@@ -1673,10 +1673,11 @@ static void test_async_file_errors(void)
static
void
test_read_write
(
void
)
{
DWORD
bytes
,
ret
;
DWORD
bytes
,
ret
,
old_prot
;
HANDLE
hFile
;
char
temp_path
[
MAX_PATH
];
char
filename
[
MAX_PATH
];
char
*
mem
;
static
const
char
prefix
[]
=
"pfx"
;
ret
=
GetTempPathA
(
MAX_PATH
,
temp_path
);
...
...
@@ -1726,6 +1727,95 @@ static void test_read_write(void)
"ret = %d, error %d
\n
"
,
ret
,
GetLastError
());
ok
(
!
bytes
,
"bytes = %d
\n
"
,
bytes
);
/* test passing protected memory as buffer */
mem
=
VirtualAlloc
(
NULL
,
0x4000
,
MEM_COMMIT
,
PAGE_READWRITE
);
ok
(
mem
!=
NULL
,
"failed to allocate virtual mem error %u
\n
"
,
GetLastError
()
);
ret
=
WriteFile
(
hFile
,
mem
,
0x4000
,
&
bytes
,
NULL
);
ok
(
ret
,
"WriteFile failed error %u
\n
"
,
GetLastError
()
);
ok
(
bytes
==
0x4000
,
"only wrote %x bytes
\n
"
,
bytes
);
ret
=
VirtualProtect
(
mem
+
0x2000
,
0x2000
,
PAGE_NOACCESS
,
&
old_prot
);
ok
(
ret
,
"VirtualProtect failed error %u
\n
"
,
GetLastError
()
);
ret
=
WriteFile
(
hFile
,
mem
,
0x4000
,
&
bytes
,
NULL
);
ok
(
!
ret
,
"WriteFile succeeded
\n
"
);
ok
(
GetLastError
()
==
ERROR_INVALID_USER_BUFFER
||
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
/* win9x */
"wrong error %u
\n
"
,
GetLastError
()
);
ok
(
bytes
==
0
,
"wrote %x bytes
\n
"
,
bytes
);
ret
=
WriteFile
(
(
HANDLE
)
0xdead
,
mem
,
0x4000
,
&
bytes
,
NULL
);
ok
(
!
ret
,
"WriteFile succeeded
\n
"
);
ok
(
GetLastError
()
==
ERROR_INVALID_HANDLE
||
/* handle is checked before buffer on NT */
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
/* win9x */
"wrong error %u
\n
"
,
GetLastError
()
);
ok
(
bytes
==
0
,
"wrote %x bytes
\n
"
,
bytes
);
ret
=
VirtualProtect
(
mem
,
0x2000
,
PAGE_NOACCESS
,
&
old_prot
);
ok
(
ret
,
"VirtualProtect failed error %u
\n
"
,
GetLastError
()
);
ret
=
WriteFile
(
hFile
,
mem
,
0x4000
,
&
bytes
,
NULL
);
ok
(
!
ret
,
"WriteFile succeeded
\n
"
);
ok
(
GetLastError
()
==
ERROR_INVALID_USER_BUFFER
||
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
/* win9x */
"wrong error %u
\n
"
,
GetLastError
()
);
ok
(
bytes
==
0
,
"wrote %x bytes
\n
"
,
bytes
);
SetFilePointer
(
hFile
,
0
,
NULL
,
FILE_BEGIN
);
ret
=
ReadFile
(
hFile
,
mem
,
0x4000
,
&
bytes
,
NULL
);
ok
(
!
ret
,
"ReadFile succeeded
\n
"
);
ok
(
GetLastError
()
==
ERROR_NOACCESS
||
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
/* win9x */
"wrong error %u
\n
"
,
GetLastError
()
);
ok
(
bytes
==
0
,
"read %x bytes
\n
"
,
bytes
);
ret
=
VirtualProtect
(
mem
,
0x2000
,
PAGE_READONLY
,
&
old_prot
);
ok
(
ret
,
"VirtualProtect failed error %u
\n
"
,
GetLastError
()
);
ret
=
ReadFile
(
hFile
,
mem
,
0x4000
,
&
bytes
,
NULL
);
ok
(
!
ret
,
"ReadFile succeeded
\n
"
);
ok
(
GetLastError
()
==
ERROR_NOACCESS
||
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
/* win9x */
"wrong error %u
\n
"
,
GetLastError
()
);
ok
(
bytes
==
0
,
"read %x bytes
\n
"
,
bytes
);
ret
=
VirtualProtect
(
mem
,
0x2000
,
PAGE_READWRITE
,
&
old_prot
);
ok
(
ret
,
"VirtualProtect failed error %u
\n
"
,
GetLastError
()
);
ret
=
ReadFile
(
hFile
,
mem
,
0x4000
,
&
bytes
,
NULL
);
ok
(
!
ret
,
"ReadFile succeeded
\n
"
);
ok
(
GetLastError
()
==
ERROR_NOACCESS
||
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
/* win9x */
"wrong error %u
\n
"
,
GetLastError
()
);
ok
(
bytes
==
0
,
"read %x bytes
\n
"
,
bytes
);
SetFilePointer
(
hFile
,
0x1234
,
NULL
,
FILE_BEGIN
);
SetEndOfFile
(
hFile
);
SetFilePointer
(
hFile
,
0
,
NULL
,
FILE_BEGIN
);
ret
=
ReadFile
(
hFile
,
mem
,
0x4000
,
&
bytes
,
NULL
);
ok
(
!
ret
,
"ReadFile succeeded
\n
"
);
ok
(
GetLastError
()
==
ERROR_NOACCESS
||
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
/* win9x */
"wrong error %u
\n
"
,
GetLastError
()
);
ok
(
bytes
==
0
,
"read %x bytes
\n
"
,
bytes
);
ret
=
ReadFile
(
hFile
,
mem
,
0x2000
,
&
bytes
,
NULL
);
ok
(
ret
,
"ReadFile failed error %u
\n
"
,
GetLastError
()
);
ok
(
bytes
==
0x1234
,
"read %x bytes
\n
"
,
bytes
);
ret
=
ReadFile
(
hFile
,
NULL
,
1
,
&
bytes
,
NULL
);
ok
(
!
ret
,
"ReadFile succeeded
\n
"
);
ok
(
GetLastError
()
==
ERROR_NOACCESS
||
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
/* win9x */
"wrong error %u
\n
"
,
GetLastError
()
);
ok
(
bytes
==
0
,
"read %x bytes
\n
"
,
bytes
);
VirtualFree
(
mem
,
0
,
MEM_FREE
);
ret
=
CloseHandle
(
hFile
);
ok
(
ret
,
"CloseHandle: error %d
\n
"
,
GetLastError
());
ret
=
DeleteFileA
(
filename
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment