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
a8b8ddd8
Commit
a8b8ddd8
authored
Sep 26, 2007
by
Mikolaj Zalewski
Committed by
Alexandre Julliard
Sep 28, 2007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
advapi32: Fix GetServiceDisplayNameA for cchBuffer == 0.
parent
8fd1cf0f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
30 deletions
+28
-30
service.c
dlls/advapi32/service.c
+20
-29
service.c
dlls/advapi32/tests/service.c
+8
-1
No files found.
dlls/advapi32/service.c
View file @
a8b8ddd8
...
...
@@ -2231,49 +2231,40 @@ BOOL WINAPI QueryServiceLockStatusW( SC_HANDLE hSCManager,
BOOL
WINAPI
GetServiceDisplayNameA
(
SC_HANDLE
hSCManager
,
LPCSTR
lpServiceName
,
LPSTR
lpDisplayName
,
LPDWORD
lpcchBuffer
)
{
LPWSTR
lpServiceNameW
,
lpDisplayNameW
=
NULL
;
DWORD
size
,
sizeW
,
GLE
;
BOOL
ret
;
LPWSTR
lpServiceNameW
,
lpDisplayNameW
;
DWORD
size
W
;
BOOL
ret
=
FALSE
;
TRACE
(
"%p %s %p %p
\n
"
,
hSCManager
,
debugstr_a
(
lpServiceName
),
lpDisplayName
,
lpcchBuffer
);
lpServiceNameW
=
SERV_dup
(
lpServiceName
);
lpDisplayNameW
=
HeapAlloc
(
GetProcessHeap
(),
0
,
*
lpcchBuffer
*
sizeof
(
WCHAR
));
size
=
sizeW
=
*
lpcchBuffer
;
ret
=
GetServiceDisplayNameW
(
hSCManager
,
lpServiceNameW
,
lpDisplayName
?
lpDisplayNameW
:
NULL
,
&
sizeW
);
/* Last error will be set by GetServiceDisplayNameW and must be preserved */
GLE
=
GetLastError
();
if
(
lpDisplayName
)
lpDisplayNameW
=
HeapAlloc
(
GetProcessHeap
(),
0
,
*
lpcchBuffer
*
sizeof
(
WCHAR
));
else
lpDisplayNameW
=
NULL
;
if
(
!
lpDisplayName
&&
*
lpcchBuffer
&&
!
ret
&&
(
GLE
==
ERROR_INSUFFICIENT_BUFFER
))
sizeW
=
*
lpcchBuffer
;
if
(
!
GetServiceDisplayNameW
(
hSCManager
,
lpServiceNameW
,
lpDisplayNameW
,
&
sizeW
))
{
/* Request for buffersize.
*
* Only set the size for ERROR_INSUFFICIENT_BUFFER
*/
size
=
sizeW
*
2
;
*
lpcchBuffer
=
sizeW
*
2
;
/* we can only provide an upper estimation of string length */
goto
cleanup
;
}
else
if
(
lpDisplayName
&&
*
lpcchBuffer
&&
!
ret
)
if
(
!
WideCharToMultiByte
(
CP_ACP
,
0
,
lpDisplayNameW
,
(
sizeW
+
1
),
lpDisplayName
,
*
lpcchBuffer
,
NULL
,
NULL
))
{
/* Request for displayname.
*
* size only has to be set if this fails
*/
size
=
sizeW
*
2
;
*
lpcchBuffer
=
WideCharToMultiByte
(
CP_ACP
,
0
,
lpDisplayNameW
,
-
1
,
NULL
,
0
,
NULL
,
NULL
);
goto
cleanup
;
}
WideCharToMultiByte
(
CP_ACP
,
0
,
lpDisplayNameW
,
(
sizeW
+
1
),
lpDisplayName
,
*
lpcchBuffer
,
NULL
,
NULL
);
*
lpcchBuffer
=
size
;
/* probably due to a bug GetServiceDisplayNameA doesn't modify lpcchBuffer on success.
* (but if the function succeeded it means that is a good upper estimation of the size) */
ret
=
TRUE
;
cleanup:
HeapFree
(
GetProcessHeap
(),
0
,
lpDisplayNameW
);
HeapFree
(
GetProcessHeap
(),
0
,
lpServiceNameW
);
SetLastError
(
GLE
);
return
ret
;
}
...
...
dlls/advapi32/tests/service.c
View file @
a8b8ddd8
...
...
@@ -444,10 +444,17 @@ static void test_get_displayname(void)
ok
(
!
ret
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
ERROR_INSUFFICIENT_BUFFER
,
"Expected ERROR_INSUFFICIENT_BUFFER, got %d
\n
"
,
GetLastError
());
tempsize
=
displaysize
;
displaysize
=
0
;
ret
=
GetServiceDisplayNameA
(
scm_handle
,
spooler
,
NULL
,
&
displaysize
);
ok
(
!
ret
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
ERROR_INSUFFICIENT_BUFFER
,
"Expected ERROR_INSUFFICIENT_BUFFER, got %d
\n
"
,
GetLastError
());
ok
(
displaysize
==
tempsize
,
"Buffer size mismatch (%d vs %d)
\n
"
,
tempsize
,
displaysize
);
/* Buffer is too small */
SetLastError
(
0xdeadbeef
);
tempsize
=
displaysize
;
displaysize
=
(
tempsize
/
2
);
ret
=
GetServiceDisplayNameA
(
scm_handle
,
spooler
,
displayname
,
&
displaysize
);
ok
(
!
ret
,
"Expected failure
\n
"
);
...
...
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