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
969515d0
Commit
969515d0
authored
Oct 02, 2000
by
Lawson Whitney
Committed by
Alexandre Julliard
Oct 02, 2000
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Protect GlobalHandle() against bad parameters.
parent
df12a0d6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
24 deletions
+53
-24
global.c
memory/global.c
+53
-24
No files found.
memory/global.c
View file @
969515d0
...
...
@@ -13,6 +13,7 @@
#include <string.h>
#include "wine/winbase16.h"
#include "wine/exception.h"
#include "global.h"
#include "heap.h"
#include "toolhelp.h"
...
...
@@ -54,6 +55,21 @@ static int globalArenaSize = 0;
#define VALID_HANDLE(handle) (((handle)>>__AHSHIFT)<globalArenaSize)
#define GET_ARENA_PTR(handle) (pGlobalArena + ((handle) >> __AHSHIFT))
/* filter for page-fault exceptions */
/* It is possible for a bogus global pointer to cause a */
/* page zero reference, so I include EXCEPTION_PRIV_INSTRUCTION too. */
static
WINE_EXCEPTION_FILTER
(
page_fault
)
{
switch
(
GetExceptionCode
())
{
case
(
EXCEPTION_ACCESS_VIOLATION
):
case
(
EXCEPTION_PRIV_INSTRUCTION
):
return
EXCEPTION_EXECUTE_HANDLER
;
default:
return
EXCEPTION_CONTINUE_SEARCH
;
}
}
/***********************************************************************
* GLOBAL_GetArena
*
...
...
@@ -1151,34 +1167,47 @@ HGLOBAL WINAPI GlobalHandle(
if
(
!
pmem
)
{
SetLastError
(
ERROR_INVALID_PARAMETER
);
return
0
;
SetLastError
(
ERROR_INVALID_PARAMETER
);
return
0
;
}
/* note that if pmem is a pointer to a a block allocated by */
/* GlobalAlloc with GMEM_MOVEABLE then magic test in HeapValidate */
/* will fail. */
if
(
ISPOINTER
(
pmem
))
{
heap
=
GLOBAL_GetHeap
(
(
HGLOBAL
)
pmem
);
if
(
HeapValidate
(
heap
,
0
,
pmem
))
return
(
HGLOBAL
)
pmem
;
/* valid fixed block */
handle
=
POINTER_TO_HANDLE
(
pmem
);
}
else
handle
=
(
HGLOBAL
)
pmem
;
/* Now test handle either passed in or retrieved from pointer */
heap
=
GLOBAL_GetHeap
(
handle
);
maybe_intern
=
HANDLE_TO_INTERN
(
handle
);
if
(
maybe_intern
->
Magic
==
MAGIC_GLOBAL_USED
)
{
test
=
maybe_intern
->
Pointer
;
if
(
HeapValidate
(
heap
,
0
,
((
HGLOBAL
*
)
test
)
-
1
)
&&
/* obj(-handle) valid arena? */
HeapValidate
(
heap
,
0
,
maybe_intern
))
/* intern valid arena? */
return
handle
;
/* valid moveable block */
__TRY
{
handle
=
0
;
/* note that if pmem is a pointer to a a block allocated by */
/* GlobalAlloc with GMEM_MOVEABLE then magic test in HeapValidate */
/* will fail. */
if
(
ISPOINTER
(
pmem
))
{
heap
=
GLOBAL_GetHeap
(
(
HGLOBAL
)
pmem
);
if
(
HeapValidate
(
heap
,
0
,
pmem
))
{
handle
=
(
HGLOBAL
)
pmem
;
/* valid fixed block */
break
;
}
handle
=
POINTER_TO_HANDLE
(
pmem
);
}
else
handle
=
(
HGLOBAL
)
pmem
;
/* Now test handle either passed in or retrieved from pointer */
heap
=
GLOBAL_GetHeap
(
handle
);
maybe_intern
=
HANDLE_TO_INTERN
(
handle
);
if
(
maybe_intern
->
Magic
==
MAGIC_GLOBAL_USED
)
{
test
=
maybe_intern
->
Pointer
;
if
(
HeapValidate
(
heap
,
0
,
((
HGLOBAL
*
)
test
)
-
1
)
&&
/* obj(-handle) valid arena? */
HeapValidate
(
heap
,
0
,
maybe_intern
))
/* intern valid arena? */
break
;
/* valid moveable block */
}
handle
=
0
;
SetLastError
(
ERROR_INVALID_HANDLE
);
}
__EXCEPT
(
page_fault
)
{
SetLastError
(
ERROR_INVALID_HANDLE
);
return
0
;
}
__ENDTRY
SetLastError
(
ERROR_INVALID_HANDLE
);
return
0
;
return
handle
;
}
...
...
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