[Bug 51264] GUI exe receives invalid StdOutput HANDLE if launched via ShellExecuteEx

WineHQ Bugzilla wine-bugs at winehq.org
Tue Jun 15 05:29:07 CDT 2021


https://bugs.winehq.org/show_bug.cgi?id=51264

--- Comment #2 from Brendan McGrath <brendan at redmandi.com> ---
Investigating this further, I found that when running this test program with
'wine', hStdOutput in 'main.exe' is assigned the value of 0x14 (see
'create_process_params').

This value is then passed to 'child.exe', but it is an invalid handle (because
handles are not being inherited).

During LdrInitializeThunk of 'child.exe', handle 0x14 is then used (in a
collision) for the CurrentDirectory value in RtlSetCurrentDirectory_U.

As a result, hStdOutput in 'child.exe' now points to a directory and any
attempt to write to the console now causes an error (and a crash when using
wine-mono).

I don't see this problem when running with 'wine64', as hStdOutput in
'main.exe' is assigned the value of 0x30 (which does not result in a collision)
and msvcrt_init_io performs a clean-up (thus hStdOutput is set to 0, which is
the same value seen when running this test program on Windows). But this
appears to be by chance rather than design.

I also don't see this problem when the PE header in child.exe has a subsystem
value of IMAGE_SUBSYSTEM_WINDOWS_CUI (as opposed to GUI) because init_console
runs 'AllocConsole' under this condition (which results in a new hStdOutput
value being assigned; see 'init_console_std_handles').

I can see in server/process.c (under 'new_process') that the handles will be
duplicated under the following condition:
if (!(req->flags & PROCESS_CREATE_FLAGS_INHERIT_HANDLES) && info->data->console
!= 1)

So I believe create_process_params can be modified to not pass the value of the
StdHandles if 'inherit' is false and 'flags' has CREATE_NEW_CONSOLE switched on
(as under this condition, the StdHandles never appear to be inherited).

-- 
Do not reply to this email, post in Bugzilla using the
above URL to reply.
You are receiving this mail because:
You are watching all bug changes.



More information about the wine-bugs mailing list