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
458f49de
Commit
458f49de
authored
Mar 31, 2022
by
Rémi Bernon
Committed by
Alexandre Julliard
Mar 31, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernelbase: Check handle validity in unsafe_mem_from_HLOCAL.
Signed-off-by:
Rémi Bernon
<
rbernon@codeweavers.com
>
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
0d8ebada
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
memory.c
dlls/kernelbase/memory.c
+13
-12
No files found.
dlls/kernelbase/memory.c
View file @
458f49de
...
...
@@ -598,9 +598,12 @@ struct mem_entry
* the output jpeg's > 1 MB if not */
#define HLOCAL_STORAGE (sizeof(HLOCAL) * 2)
static
inline
struct
mem_entry
*
mem_from_HLOCAL
(
HLOCAL
handle
)
static
inline
struct
mem_entry
*
unsafe_
mem_from_HLOCAL
(
HLOCAL
handle
)
{
return
(
struct
mem_entry
*
)((
char
*
)
handle
-
2
);
struct
mem_entry
*
mem
=
CONTAINING_RECORD
(
handle
,
struct
mem_entry
,
ptr
);
if
(
!
((
ULONG_PTR
)
handle
&
2
))
return
NULL
;
if
(
mem
->
magic
!=
MAGIC_LOCAL_USED
)
return
NULL
;
return
mem
;
}
static
inline
HLOCAL
HLOCAL_from_mem
(
struct
mem_entry
*
mem
)
...
...
@@ -709,8 +712,7 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalFree( HLOCAL handle )
}
else
/* HANDLE */
{
mem
=
mem_from_HLOCAL
(
handle
);
if
(
mem
->
magic
==
MAGIC_LOCAL_USED
)
if
((
mem
=
unsafe_mem_from_HLOCAL
(
handle
)))
{
mem
->
magic
=
0xdead
;
if
(
mem
->
ptr
)
...
...
@@ -745,6 +747,7 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalFree( HLOCAL handle )
*/
LPVOID
WINAPI
DECLSPEC_HOTPATCH
LocalLock
(
HLOCAL
handle
)
{
struct
mem_entry
*
mem
;
void
*
ret
=
NULL
;
TRACE_
(
globalmem
)(
"handle %p
\n
"
,
handle
);
...
...
@@ -767,8 +770,7 @@ LPVOID WINAPI DECLSPEC_HOTPATCH LocalLock( HLOCAL handle )
RtlLockHeap
(
GetProcessHeap
()
);
__TRY
{
struct
mem_entry
*
mem
=
mem_from_HLOCAL
(
handle
);
if
(
mem
->
magic
==
MAGIC_LOCAL_USED
)
if
((
mem
=
unsafe_mem_from_HLOCAL
(
handle
)))
{
ret
=
mem
->
ptr
;
if
(
!
mem
->
ptr
)
SetLastError
(
ERROR_DISCARDED
);
...
...
@@ -826,10 +828,9 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalReAlloc( HLOCAL handle, SIZE_T size, UINT f
LocalFree
(
handle
);
}
}
else
if
(
!
is_pointer
(
handle
)
&&
(
flags
&
LMEM_DISCARDABLE
))
else
if
(
(
mem
=
unsafe_mem_from_HLOCAL
(
handle
)
)
&&
(
flags
&
LMEM_DISCARDABLE
))
{
/* change the flags to make our block "discardable" */
mem
=
mem_from_HLOCAL
(
handle
);
mem
->
flags
|=
LMEM_DISCARDABLE
>>
8
;
ret
=
handle
;
}
...
...
@@ -843,10 +844,9 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalReAlloc( HLOCAL handle, SIZE_T size, UINT f
if
(
!
(
flags
&
LMEM_MOVEABLE
))
heap_flags
|=
HEAP_REALLOC_IN_PLACE_ONLY
;
ret
=
HeapReAlloc
(
GetProcessHeap
(),
heap_flags
,
handle
,
size
);
}
else
else
if
((
mem
=
unsafe_mem_from_HLOCAL
(
handle
)))
{
/* reallocate a moveable block */
mem
=
mem_from_HLOCAL
(
handle
);
if
(
size
!=
0
)
{
if
(
size
<=
INT_MAX
-
HLOCAL_STORAGE
)
...
...
@@ -886,6 +886,7 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalReAlloc( HLOCAL handle, SIZE_T size, UINT f
else
WARN_
(
globalmem
)(
"not freeing memory associated with locked handle
\n
"
);
}
}
else
SetLastError
(
ERROR_INVALID_HANDLE
);
}
RtlUnlockHeap
(
GetProcessHeap
()
);
return
ret
;
...
...
@@ -897,6 +898,7 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalReAlloc( HLOCAL handle, SIZE_T size, UINT f
*/
BOOL
WINAPI
DECLSPEC_HOTPATCH
LocalUnlock
(
HLOCAL
handle
)
{
struct
mem_entry
*
mem
;
BOOL
ret
=
FALSE
;
TRACE_
(
globalmem
)(
"handle %p
\n
"
,
handle
);
...
...
@@ -910,8 +912,7 @@ BOOL WINAPI DECLSPEC_HOTPATCH LocalUnlock( HLOCAL handle )
RtlLockHeap
(
GetProcessHeap
()
);
__TRY
{
struct
mem_entry
*
mem
=
mem_from_HLOCAL
(
handle
);
if
(
mem
->
magic
==
MAGIC_LOCAL_USED
)
if
((
mem
=
unsafe_mem_from_HLOCAL
(
handle
)))
{
if
(
mem
->
lock
)
{
...
...
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