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
82cfed96
Commit
82cfed96
authored
May 17, 2007
by
Rob Shearman
Committed by
Alexandre Julliard
May 18, 2007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ole32: Fix reading from an HGLOBALStreamImpl with an invalid HGLOBAL.
Add tests that show the strange behaviour of IStream_Read returning S_OK instead of an error code.
parent
600143d4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
0 deletions
+58
-0
hglobalstream.c
dlls/ole32/hglobalstream.c
+13
-0
hglobalstream.c
dlls/ole32/tests/hglobalstream.c
+45
-0
No files found.
dlls/ole32/hglobalstream.c
View file @
82cfed96
...
...
@@ -233,6 +233,12 @@ static HRESULT WINAPI HGLOBALStreamImpl_Read(
* Lock the buffer in position and copy the data.
*/
supportBuffer
=
GlobalLock
(
This
->
supportHandle
);
if
(
!
supportBuffer
)
{
WARN
(
"read from invalid hglobal %p
\n
"
,
This
->
supportHandle
);
*
pcbRead
=
0
;
return
S_OK
;
}
memcpy
(
pv
,
(
char
*
)
supportBuffer
+
This
->
currentPosition
.
u
.
LowPart
,
bytesToReadFromBuffer
);
...
...
@@ -293,6 +299,8 @@ static HRESULT WINAPI HGLOBALStreamImpl_Write(
if
(
cb
==
0
)
goto
out
;
*
pcbWritten
=
0
;
newSize
.
u
.
HighPart
=
0
;
newSize
.
u
.
LowPart
=
This
->
currentPosition
.
u
.
LowPart
+
cb
;
...
...
@@ -314,6 +322,11 @@ static HRESULT WINAPI HGLOBALStreamImpl_Write(
* Lock the buffer in position and copy the data.
*/
supportBuffer
=
GlobalLock
(
This
->
supportHandle
);
if
(
!
supportBuffer
)
{
WARN
(
"write to invalid hglobal %p
\n
"
,
This
->
supportHandle
);
return
S_OK
;
}
memcpy
((
char
*
)
supportBuffer
+
This
->
currentPosition
.
u
.
LowPart
,
pv
,
cb
);
...
...
dlls/ole32/tests/hglobalstream.c
View file @
82cfed96
...
...
@@ -259,6 +259,50 @@ static void test_copyto(void)
IStream_Release
(
pStream
);
}
static
void
test_freed_hglobal
(
void
)
{
HRESULT
hr
;
IStream
*
pStream
;
HGLOBAL
hglobal
;
char
*
p
;
char
buffer
[
10
];
ULARGE_INTEGER
ull
;
ULONG
read
,
written
;
hglobal
=
GlobalAlloc
(
GMEM_DDESHARE
|
GMEM_NODISCARD
|
GMEM_MOVEABLE
,
strlen
(
"Rob"
)
+
1
);
ok
(
hglobal
!=
NULL
,
"GlobalAlloc failed with error %d
\n
"
,
GetLastError
());
p
=
GlobalLock
(
hglobal
);
strcpy
(
p
,
"Rob"
);
GlobalUnlock
(
hglobal
);
hr
=
CreateStreamOnHGlobal
(
hglobal
,
FALSE
,
&
pStream
);
ok_ole_success
(
hr
,
"CreateStreamOnHGlobal"
);
hr
=
IStream_Read
(
pStream
,
buffer
,
sizeof
(
buffer
),
&
read
);
ok_ole_success
(
hr
,
"IStream_Read"
);
ok
(
!
strcmp
(
buffer
,
"Rob"
),
"buffer data %s differs
\n
"
,
buffer
);
ok
(
read
==
strlen
(
"Rob"
)
+
1
,
"read should be 4 instead of %d
\n
"
,
read
);
GlobalFree
(
hglobal
);
memset
(
buffer
,
0
,
sizeof
(
buffer
));
read
=
-
1
;
hr
=
IStream_Read
(
pStream
,
buffer
,
sizeof
(
buffer
),
&
read
);
ok_ole_success
(
hr
,
"IStream_Read"
);
ok
(
buffer
[
0
]
==
0
,
"buffer data should be untouched
\n
"
);
ok
(
read
==
0
,
"read should be 0 instead of %d
\n
"
,
read
);
ull
.
QuadPart
=
sizeof
(
buffer
);
hr
=
IStream_SetSize
(
pStream
,
ull
);
ok
(
hr
==
E_OUTOFMEMORY
,
"IStream_SetSize with invalid HGLOBAL should return E_OUTOFMEMORY instead of 0x%08x
\n
"
,
hr
);
hr
=
IStream_Write
(
pStream
,
buffer
,
sizeof
(
buffer
),
&
written
);
ok
(
hr
==
E_OUTOFMEMORY
,
"IStream_Write with invalid HGLOBAL should return E_OUTOFMEMORY instead of 0x%08x
\n
"
,
hr
);
ok
(
written
==
0
,
"written should be 0 instead of %d
\n
"
,
written
);
IStream_Release
(
pStream
);
}
START_TEST
(
hglobalstream
)
{
HRESULT
hr
;
...
...
@@ -270,4 +314,5 @@ START_TEST(hglobalstream)
test_streamonhglobal
(
pStream
);
IStream_Release
(
pStream
);
test_copyto
();
test_freed_hglobal
();
}
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