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
21876b99
Commit
21876b99
authored
Jan 13, 2020
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernel32: Catch stack overflow faults in IsBad*Ptr() functions.
Wine-Bug:
https://bugs.winehq.org/show_bug.cgi?id=48444
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
0778945e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
6 deletions
+35
-6
virtual.c
dlls/kernel32/tests/virtual.c
+12
-0
virtual.c
dlls/kernel32/virtual.c
+23
-6
No files found.
dlls/kernel32/tests/virtual.c
View file @
21876b99
...
@@ -1533,6 +1533,12 @@ static void test_IsBadReadPtr(void)
...
@@ -1533,6 +1533,12 @@ static void test_IsBadReadPtr(void)
ret
=
IsBadReadPtr
(
&
stackvar
,
sizeof
(
char
));
ret
=
IsBadReadPtr
(
&
stackvar
,
sizeof
(
char
));
ok
(
ret
==
FALSE
,
"Expected IsBadReadPtr to return FALSE, got %d
\n
"
,
ret
);
ok
(
ret
==
FALSE
,
"Expected IsBadReadPtr to return FALSE, got %d
\n
"
,
ret
);
ret
=
IsBadReadPtr
((
char
*
)
NtCurrentTeb
()
->
DeallocationStack
+
4096
,
sizeof
(
DWORD
));
ok
(
ret
==
TRUE
,
"Expected IsBadReadPtr to return TRUE, got %d
\n
"
,
ret
);
ret
=
IsBadReadPtr
((
char
*
)
NtCurrentTeb
()
->
DeallocationStack
+
4096
,
sizeof
(
DWORD
));
ok
(
ret
==
TRUE
,
"Expected IsBadReadPtr to return TRUE, got %d
\n
"
,
ret
);
}
}
static
void
test_IsBadWritePtr
(
void
)
static
void
test_IsBadWritePtr
(
void
)
...
@@ -1558,6 +1564,12 @@ static void test_IsBadWritePtr(void)
...
@@ -1558,6 +1564,12 @@ static void test_IsBadWritePtr(void)
ret
=
IsBadWritePtr
(
&
stackval
,
sizeof
(
char
));
ret
=
IsBadWritePtr
(
&
stackval
,
sizeof
(
char
));
ok
(
ret
==
FALSE
,
"Expected IsBadWritePtr to return FALSE, got %d
\n
"
,
ret
);
ok
(
ret
==
FALSE
,
"Expected IsBadWritePtr to return FALSE, got %d
\n
"
,
ret
);
ret
=
IsBadWritePtr
((
char
*
)
NtCurrentTeb
()
->
DeallocationStack
+
4096
,
sizeof
(
DWORD
));
ok
(
ret
==
TRUE
,
"Expected IsBadWritePtr to return TRUE, got %d
\n
"
,
ret
);
ret
=
IsBadWritePtr
((
char
*
)
NtCurrentTeb
()
->
DeallocationStack
+
4096
,
sizeof
(
DWORD
));
ok
(
ret
==
TRUE
,
"Expected IsBadWritePtr to return TRUE, got %d
\n
"
,
ret
);
}
}
static
void
test_IsBadCodePtr
(
void
)
static
void
test_IsBadCodePtr
(
void
)
...
...
dlls/kernel32/virtual.c
View file @
21876b99
...
@@ -48,6 +48,23 @@ WINE_DECLARE_DEBUG_CHANNEL(seh);
...
@@ -48,6 +48,23 @@ WINE_DECLARE_DEBUG_CHANNEL(seh);
WINE_DECLARE_DEBUG_CHANNEL
(
file
);
WINE_DECLARE_DEBUG_CHANNEL
(
file
);
static
LONG
WINAPI
badptr_handler
(
EXCEPTION_POINTERS
*
eptr
)
{
EXCEPTION_RECORD
*
rec
=
eptr
->
ExceptionRecord
;
if
(
rec
->
ExceptionCode
==
STATUS_ACCESS_VIOLATION
)
return
EXCEPTION_EXECUTE_HANDLER
;
if
(
rec
->
ExceptionCode
==
STATUS_STACK_OVERFLOW
)
{
/* restore stack guard page */
void
*
addr
=
(
char
*
)
NtCurrentTeb
()
->
DeallocationStack
+
system_info
.
PageSize
;
SIZE_T
size
=
(
char
*
)
rec
-
(
char
*
)
addr
;
ULONG
old_prot
;
NtProtectVirtualMemory
(
GetCurrentProcess
(),
&
addr
,
&
size
,
PAGE_GUARD
|
PAGE_READWRITE
,
&
old_prot
);
return
EXCEPTION_EXECUTE_HANDLER
;
}
return
EXCEPTION_CONTINUE_SEARCH
;
}
/***********************************************************************
/***********************************************************************
* IsBadReadPtr (KERNEL32.@)
* IsBadReadPtr (KERNEL32.@)
*
*
...
@@ -79,7 +96,7 @@ BOOL WINAPI IsBadReadPtr( LPCVOID ptr, UINT_PTR size )
...
@@ -79,7 +96,7 @@ BOOL WINAPI IsBadReadPtr( LPCVOID ptr, UINT_PTR size )
dummy
=
p
[
0
];
dummy
=
p
[
0
];
dummy
=
p
[
count
-
1
];
dummy
=
p
[
count
-
1
];
}
}
__EXCEPT
_PAGE_FAULT
__EXCEPT
(
badptr_handler
)
{
{
TRACE_
(
seh
)(
"%p caused page fault during read
\n
"
,
ptr
);
TRACE_
(
seh
)(
"%p caused page fault during read
\n
"
,
ptr
);
return
TRUE
;
return
TRUE
;
...
@@ -120,7 +137,7 @@ BOOL WINAPI IsBadWritePtr( LPVOID ptr, UINT_PTR size )
...
@@ -120,7 +137,7 @@ BOOL WINAPI IsBadWritePtr( LPVOID ptr, UINT_PTR size )
p
[
0
]
|=
0
;
p
[
0
]
|=
0
;
p
[
count
-
1
]
|=
0
;
p
[
count
-
1
]
|=
0
;
}
}
__EXCEPT
_PAGE_FAULT
__EXCEPT
(
badptr_handler
)
{
{
TRACE_
(
seh
)(
"%p caused page fault during write
\n
"
,
ptr
);
TRACE_
(
seh
)(
"%p caused page fault during write
\n
"
,
ptr
);
return
TRUE
;
return
TRUE
;
...
@@ -202,13 +219,13 @@ BOOL WINAPI IsBadCodePtr( FARPROC ptr )
...
@@ -202,13 +219,13 @@ BOOL WINAPI IsBadCodePtr( FARPROC ptr )
BOOL
WINAPI
IsBadStringPtrA
(
LPCSTR
str
,
UINT_PTR
max
)
BOOL
WINAPI
IsBadStringPtrA
(
LPCSTR
str
,
UINT_PTR
max
)
{
{
if
(
!
str
)
return
TRUE
;
if
(
!
str
)
return
TRUE
;
__TRY
__TRY
{
{
volatile
const
char
*
p
=
str
;
volatile
const
char
*
p
=
str
;
while
(
p
!=
str
+
max
)
if
(
!*
p
++
)
break
;
while
(
p
!=
str
+
max
)
if
(
!*
p
++
)
break
;
}
}
__EXCEPT
_PAGE_FAULT
__EXCEPT
(
badptr_handler
)
{
{
TRACE_
(
seh
)(
"%p caused page fault during read
\n
"
,
str
);
TRACE_
(
seh
)(
"%p caused page fault during read
\n
"
,
str
);
return
TRUE
;
return
TRUE
;
...
@@ -226,13 +243,13 @@ BOOL WINAPI IsBadStringPtrA( LPCSTR str, UINT_PTR max )
...
@@ -226,13 +243,13 @@ BOOL WINAPI IsBadStringPtrA( LPCSTR str, UINT_PTR max )
BOOL
WINAPI
IsBadStringPtrW
(
LPCWSTR
str
,
UINT_PTR
max
)
BOOL
WINAPI
IsBadStringPtrW
(
LPCWSTR
str
,
UINT_PTR
max
)
{
{
if
(
!
str
)
return
TRUE
;
if
(
!
str
)
return
TRUE
;
__TRY
__TRY
{
{
volatile
const
WCHAR
*
p
=
str
;
volatile
const
WCHAR
*
p
=
str
;
while
(
p
!=
str
+
max
)
if
(
!*
p
++
)
break
;
while
(
p
!=
str
+
max
)
if
(
!*
p
++
)
break
;
}
}
__EXCEPT
_PAGE_FAULT
__EXCEPT
(
badptr_handler
)
{
{
TRACE_
(
seh
)(
"%p caused page fault during read
\n
"
,
str
);
TRACE_
(
seh
)(
"%p caused page fault during read
\n
"
,
str
);
return
TRUE
;
return
TRUE
;
...
...
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