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
Show 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
...
@@ -598,9 +598,12 @@ struct mem_entry
* the output jpeg's > 1 MB if not */
* the output jpeg's > 1 MB if not */
#define HLOCAL_STORAGE (sizeof(HLOCAL) * 2)
#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
)
static
inline
HLOCAL
HLOCAL_from_mem
(
struct
mem_entry
*
mem
)
...
@@ -709,8 +712,7 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalFree( HLOCAL handle )
...
@@ -709,8 +712,7 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalFree( HLOCAL handle )
}
}
else
/* HANDLE */
else
/* HANDLE */
{
{
mem
=
mem_from_HLOCAL
(
handle
);
if
((
mem
=
unsafe_mem_from_HLOCAL
(
handle
)))
if
(
mem
->
magic
==
MAGIC_LOCAL_USED
)
{
{
mem
->
magic
=
0xdead
;
mem
->
magic
=
0xdead
;
if
(
mem
->
ptr
)
if
(
mem
->
ptr
)
...
@@ -745,6 +747,7 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalFree( HLOCAL handle )
...
@@ -745,6 +747,7 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalFree( HLOCAL handle )
*/
*/
LPVOID
WINAPI
DECLSPEC_HOTPATCH
LocalLock
(
HLOCAL
handle
)
LPVOID
WINAPI
DECLSPEC_HOTPATCH
LocalLock
(
HLOCAL
handle
)
{
{
struct
mem_entry
*
mem
;
void
*
ret
=
NULL
;
void
*
ret
=
NULL
;
TRACE_
(
globalmem
)(
"handle %p
\n
"
,
handle
);
TRACE_
(
globalmem
)(
"handle %p
\n
"
,
handle
);
...
@@ -767,8 +770,7 @@ LPVOID WINAPI DECLSPEC_HOTPATCH LocalLock( HLOCAL handle )
...
@@ -767,8 +770,7 @@ LPVOID WINAPI DECLSPEC_HOTPATCH LocalLock( HLOCAL handle )
RtlLockHeap
(
GetProcessHeap
()
);
RtlLockHeap
(
GetProcessHeap
()
);
__TRY
__TRY
{
{
struct
mem_entry
*
mem
=
mem_from_HLOCAL
(
handle
);
if
((
mem
=
unsafe_mem_from_HLOCAL
(
handle
)))
if
(
mem
->
magic
==
MAGIC_LOCAL_USED
)
{
{
ret
=
mem
->
ptr
;
ret
=
mem
->
ptr
;
if
(
!
mem
->
ptr
)
SetLastError
(
ERROR_DISCARDED
);
if
(
!
mem
->
ptr
)
SetLastError
(
ERROR_DISCARDED
);
...
@@ -826,10 +828,9 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalReAlloc( HLOCAL handle, SIZE_T size, UINT f
...
@@ -826,10 +828,9 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalReAlloc( HLOCAL handle, SIZE_T size, UINT f
LocalFree
(
handle
);
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" */
/* change the flags to make our block "discardable" */
mem
=
mem_from_HLOCAL
(
handle
);
mem
->
flags
|=
LMEM_DISCARDABLE
>>
8
;
mem
->
flags
|=
LMEM_DISCARDABLE
>>
8
;
ret
=
handle
;
ret
=
handle
;
}
}
...
@@ -843,10 +844,9 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalReAlloc( HLOCAL handle, SIZE_T size, UINT f
...
@@ -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
;
if
(
!
(
flags
&
LMEM_MOVEABLE
))
heap_flags
|=
HEAP_REALLOC_IN_PLACE_ONLY
;
ret
=
HeapReAlloc
(
GetProcessHeap
(),
heap_flags
,
handle
,
size
);
ret
=
HeapReAlloc
(
GetProcessHeap
(),
heap_flags
,
handle
,
size
);
}
}
else
else
if
((
mem
=
unsafe_mem_from_HLOCAL
(
handle
)))
{
{
/* reallocate a moveable block */
/* reallocate a moveable block */
mem
=
mem_from_HLOCAL
(
handle
);
if
(
size
!=
0
)
if
(
size
!=
0
)
{
{
if
(
size
<=
INT_MAX
-
HLOCAL_STORAGE
)
if
(
size
<=
INT_MAX
-
HLOCAL_STORAGE
)
...
@@ -886,6 +886,7 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalReAlloc( HLOCAL handle, SIZE_T size, UINT f
...
@@ -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
WARN_
(
globalmem
)(
"not freeing memory associated with locked handle
\n
"
);
}
}
}
}
else
SetLastError
(
ERROR_INVALID_HANDLE
);
}
}
RtlUnlockHeap
(
GetProcessHeap
()
);
RtlUnlockHeap
(
GetProcessHeap
()
);
return
ret
;
return
ret
;
...
@@ -897,6 +898,7 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalReAlloc( HLOCAL handle, SIZE_T size, UINT f
...
@@ -897,6 +898,7 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalReAlloc( HLOCAL handle, SIZE_T size, UINT f
*/
*/
BOOL
WINAPI
DECLSPEC_HOTPATCH
LocalUnlock
(
HLOCAL
handle
)
BOOL
WINAPI
DECLSPEC_HOTPATCH
LocalUnlock
(
HLOCAL
handle
)
{
{
struct
mem_entry
*
mem
;
BOOL
ret
=
FALSE
;
BOOL
ret
=
FALSE
;
TRACE_
(
globalmem
)(
"handle %p
\n
"
,
handle
);
TRACE_
(
globalmem
)(
"handle %p
\n
"
,
handle
);
...
@@ -910,8 +912,7 @@ BOOL WINAPI DECLSPEC_HOTPATCH LocalUnlock( HLOCAL handle )
...
@@ -910,8 +912,7 @@ BOOL WINAPI DECLSPEC_HOTPATCH LocalUnlock( HLOCAL handle )
RtlLockHeap
(
GetProcessHeap
()
);
RtlLockHeap
(
GetProcessHeap
()
);
__TRY
__TRY
{
{
struct
mem_entry
*
mem
=
mem_from_HLOCAL
(
handle
);
if
((
mem
=
unsafe_mem_from_HLOCAL
(
handle
)))
if
(
mem
->
magic
==
MAGIC_LOCAL_USED
)
{
{
if
(
mem
->
lock
)
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