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
f1db8976
Commit
f1db8976
authored
Nov 06, 2023
by
Paul Gofman
Committed by
Alexandre Julliard
Nov 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernelbase: Don't inherit all the handles in conhost.exe.
parent
66dfe504
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
15 deletions
+46
-15
console.c
dlls/kernelbase/console.c
+46
-15
No files found.
dlls/kernelbase/console.c
View file @
f1db8976
...
@@ -393,10 +393,12 @@ BOOL WINAPI DECLSPEC_HOTPATCH AttachConsole( DWORD pid )
...
@@ -393,10 +393,12 @@ BOOL WINAPI DECLSPEC_HOTPATCH AttachConsole( DWORD pid )
static
BOOL
alloc_console
(
BOOL
headless
)
static
BOOL
alloc_console
(
BOOL
headless
)
{
{
SECURITY_ATTRIBUTES
inheritable_attr
=
{
sizeof
(
inheritable_attr
),
NULL
,
TRUE
};
SECURITY_ATTRIBUTES
inheritable_attr
=
{
sizeof
(
inheritable_attr
),
NULL
,
TRUE
};
STARTUPINFOW
app_si
,
console_si
;
STARTUPINFOEXW
console_si
;
STARTUPINFOW
app_si
;
HANDLE
server
,
console
=
NULL
;
HANDLE
server
,
console
=
NULL
;
WCHAR
buffer
[
1024
],
cmd
[
256
],
conhost_path
[
MAX_PATH
];
WCHAR
buffer
[
1024
],
cmd
[
256
],
conhost_path
[
MAX_PATH
];
PROCESS_INFORMATION
pi
;
PROCESS_INFORMATION
pi
;
SIZE_T
size
;
void
*
redir
;
void
*
redir
;
BOOL
ret
;
BOOL
ret
;
...
@@ -412,42 +414,50 @@ static BOOL alloc_console( BOOL headless )
...
@@ -412,42 +414,50 @@ static BOOL alloc_console( BOOL headless )
return
FALSE
;
return
FALSE
;
}
}
memset
(
&
console_si
,
0
,
sizeof
(
console_si
)
);
console_si
.
StartupInfo
.
cb
=
sizeof
(
console_si
);
InitializeProcThreadAttributeList
(
NULL
,
1
,
0
,
&
size
);
if
(
!
(
console_si
.
lpAttributeList
=
HeapAlloc
(
GetProcessHeap
(),
0
,
size
)))
return
FALSE
;
InitializeProcThreadAttributeList
(
console_si
.
lpAttributeList
,
1
,
0
,
&
size
);
if
(
!
(
server
=
create_console_server
())
||
!
(
console
=
create_console_reference
(
server
)))
goto
error
;
if
(
!
(
server
=
create_console_server
())
||
!
(
console
=
create_console_reference
(
server
)))
goto
error
;
GetStartupInfoW
(
&
app_si
);
GetStartupInfoW
(
&
app_si
);
memset
(
&
console_si
,
0
,
sizeof
(
console_si
));
console_si
.
cb
=
sizeof
(
console_si
);
/* setup a view arguments for conhost (it'll use them as default values) */
/* setup a view arguments for conhost (it'll use them as default values) */
if
(
app_si
.
dwFlags
&
STARTF_USECOUNTCHARS
)
if
(
app_si
.
dwFlags
&
STARTF_USECOUNTCHARS
)
{
{
console_si
.
dwFlags
|=
STARTF_USECOUNTCHARS
;
console_si
.
StartupInfo
.
dwFlags
|=
STARTF_USECOUNTCHARS
;
console_si
.
dwXCountChars
=
app_si
.
dwXCountChars
;
console_si
.
StartupInfo
.
dwXCountChars
=
app_si
.
dwXCountChars
;
console_si
.
dwYCountChars
=
app_si
.
dwYCountChars
;
console_si
.
StartupInfo
.
dwYCountChars
=
app_si
.
dwYCountChars
;
}
}
if
(
app_si
.
dwFlags
&
STARTF_USEFILLATTRIBUTE
)
if
(
app_si
.
dwFlags
&
STARTF_USEFILLATTRIBUTE
)
{
{
console_si
.
dwFlags
|=
STARTF_USEFILLATTRIBUTE
;
console_si
.
StartupInfo
.
dwFlags
|=
STARTF_USEFILLATTRIBUTE
;
console_si
.
dwFillAttribute
=
app_si
.
dwFillAttribute
;
console_si
.
StartupInfo
.
dwFillAttribute
=
app_si
.
dwFillAttribute
;
}
}
if
(
app_si
.
dwFlags
&
STARTF_USESHOWWINDOW
)
if
(
app_si
.
dwFlags
&
STARTF_USESHOWWINDOW
)
{
{
console_si
.
dwFlags
|=
STARTF_USESHOWWINDOW
;
console_si
.
StartupInfo
.
dwFlags
|=
STARTF_USESHOWWINDOW
;
console_si
.
wShowWindow
=
app_si
.
wShowWindow
;
console_si
.
StartupInfo
.
wShowWindow
=
app_si
.
wShowWindow
;
}
}
if
(
app_si
.
lpTitle
)
if
(
app_si
.
lpTitle
)
console_si
.
lpTitle
=
app_si
.
lpTitle
;
console_si
.
StartupInfo
.
lpTitle
=
app_si
.
lpTitle
;
else
if
(
GetModuleFileNameW
(
0
,
buffer
,
ARRAY_SIZE
(
buffer
)))
else
if
(
GetModuleFileNameW
(
0
,
buffer
,
ARRAY_SIZE
(
buffer
)))
{
{
buffer
[
ARRAY_SIZE
(
buffer
)
-
1
]
=
0
;
buffer
[
ARRAY_SIZE
(
buffer
)
-
1
]
=
0
;
console_si
.
lpTitle
=
buffer
;
console_si
.
StartupInfo
.
lpTitle
=
buffer
;
}
}
UpdateProcThreadAttribute
(
console_si
.
lpAttributeList
,
0
,
PROC_THREAD_ATTRIBUTE_HANDLE_LIST
,
&
server
,
sizeof
(
server
),
NULL
,
NULL
);
swprintf
(
conhost_path
,
ARRAY_SIZE
(
conhost_path
),
L"%s
\\
conhost.exe"
,
system_dir
);
swprintf
(
conhost_path
,
ARRAY_SIZE
(
conhost_path
),
L"%s
\\
conhost.exe"
,
system_dir
);
swprintf
(
cmd
,
ARRAY_SIZE
(
cmd
),
L"
\"
%s
\"
--server 0x%x"
,
conhost_path
,
condrv_handle
(
server
));
swprintf
(
cmd
,
ARRAY_SIZE
(
cmd
),
L"
\"
%s
\"
--server 0x%x"
,
conhost_path
,
condrv_handle
(
server
));
if
(
headless
)
wcscat
(
cmd
,
L" --headless"
);
if
(
headless
)
wcscat
(
cmd
,
L" --headless"
);
Wow64DisableWow64FsRedirection
(
&
redir
);
Wow64DisableWow64FsRedirection
(
&
redir
);
ret
=
CreateProcessW
(
conhost_path
,
cmd
,
NULL
,
NULL
,
TRUE
,
DETACHED_PROCESS
,
NULL
,
NULL
,
&
console_si
,
&
pi
);
ret
=
CreateProcessW
(
conhost_path
,
cmd
,
NULL
,
NULL
,
TRUE
,
DETACHED_PROCESS
|
EXTENDED_STARTUPINFO_PRESENT
,
NULL
,
NULL
,
&
console_si
.
StartupInfo
,
&
pi
);
Wow64RevertWow64FsRedirection
(
redir
);
Wow64RevertWow64FsRedirection
(
redir
);
if
(
!
ret
||
!
create_console_connection
(
console
))
goto
error
;
if
(
!
ret
||
!
create_console_connection
(
console
))
goto
error
;
...
@@ -456,6 +466,7 @@ static BOOL alloc_console( BOOL headless )
...
@@ -456,6 +466,7 @@ static BOOL alloc_console( BOOL headless )
RtlGetCurrentPeb
()
->
ProcessParameters
->
ConsoleHandle
=
console
;
RtlGetCurrentPeb
()
->
ProcessParameters
->
ConsoleHandle
=
console
;
TRACE
(
"Started conhost pid=%08lx tid=%08lx
\n
"
,
pi
.
dwProcessId
,
pi
.
dwThreadId
);
TRACE
(
"Started conhost pid=%08lx tid=%08lx
\n
"
,
pi
.
dwProcessId
,
pi
.
dwThreadId
);
HeapFree
(
GetProcessHeap
(),
0
,
console_si
.
lpAttributeList
);
CloseHandle
(
server
);
CloseHandle
(
server
);
RtlLeaveCriticalSection
(
&
console_section
);
RtlLeaveCriticalSection
(
&
console_section
);
SetLastError
(
ERROR_SUCCESS
);
SetLastError
(
ERROR_SUCCESS
);
...
@@ -463,6 +474,7 @@ static BOOL alloc_console( BOOL headless )
...
@@ -463,6 +474,7 @@ static BOOL alloc_console( BOOL headless )
error:
error:
ERR
(
"Can't allocate console
\n
"
);
ERR
(
"Can't allocate console
\n
"
);
HeapFree
(
GetProcessHeap
(),
0
,
console_si
.
lpAttributeList
);
NtClose
(
console
);
NtClose
(
console
);
NtClose
(
server
);
NtClose
(
server
);
FreeConsole
();
FreeConsole
();
...
@@ -2175,9 +2187,12 @@ static HANDLE create_pseudo_console( COORD size, HANDLE input, HANDLE output, HA
...
@@ -2175,9 +2187,12 @@ static HANDLE create_pseudo_console( COORD size, HANDLE input, HANDLE output, HA
DWORD
flags
,
HANDLE
*
process
)
DWORD
flags
,
HANDLE
*
process
)
{
{
WCHAR
cmd
[
MAX_PATH
],
conhost_path
[
MAX_PATH
];
WCHAR
cmd
[
MAX_PATH
],
conhost_path
[
MAX_PATH
];
unsigned
int
inherit_count
;
PROCESS_INFORMATION
pi
;
PROCESS_INFORMATION
pi
;
HANDLE
server
,
console
;
HANDLE
server
,
console
;
HANDLE
inherit
[
2
];
STARTUPINFOEXW
si
;
STARTUPINFOEXW
si
;
SIZE_T
attr_size
;
void
*
redir
;
void
*
redir
;
BOOL
res
;
BOOL
res
;
...
@@ -2196,6 +2211,21 @@ static HANDLE create_pseudo_console( COORD size, HANDLE input, HANDLE output, HA
...
@@ -2196,6 +2211,21 @@ static HANDLE create_pseudo_console( COORD size, HANDLE input, HANDLE output, HA
si
.
StartupInfo
.
hStdOutput
=
output
;
si
.
StartupInfo
.
hStdOutput
=
output
;
si
.
StartupInfo
.
hStdError
=
output
;
si
.
StartupInfo
.
hStdError
=
output
;
si
.
StartupInfo
.
dwFlags
=
STARTF_USESTDHANDLES
;
si
.
StartupInfo
.
dwFlags
=
STARTF_USESTDHANDLES
;
inherit
[
0
]
=
server
;
inherit
[
1
]
=
signal
;
inherit_count
=
signal
?
2
:
1
;
InitializeProcThreadAttributeList
(
NULL
,
inherit_count
,
0
,
&
attr_size
);
if
(
!
(
si
.
lpAttributeList
=
HeapAlloc
(
GetProcessHeap
(),
0
,
attr_size
)))
{
NtClose
(
console
);
NtClose
(
server
);
return
FALSE
;
}
InitializeProcThreadAttributeList
(
si
.
lpAttributeList
,
inherit_count
,
0
,
&
attr_size
);
UpdateProcThreadAttribute
(
si
.
lpAttributeList
,
0
,
PROC_THREAD_ATTRIBUTE_HANDLE_LIST
,
inherit
,
sizeof
(
*
inherit
)
*
inherit_count
,
NULL
,
NULL
);
swprintf
(
conhost_path
,
ARRAY_SIZE
(
conhost_path
),
L"%s
\\
conhost.exe"
,
system_dir
);
swprintf
(
conhost_path
,
ARRAY_SIZE
(
conhost_path
),
L"%s
\\
conhost.exe"
,
system_dir
);
if
(
signal
)
if
(
signal
)
{
{
...
@@ -2210,8 +2240,9 @@ static HANDLE create_pseudo_console( COORD size, HANDLE input, HANDLE output, HA
...
@@ -2210,8 +2240,9 @@ static HANDLE create_pseudo_console( COORD size, HANDLE input, HANDLE output, HA
conhost_path
,
size
.
X
,
size
.
Y
,
server
);
conhost_path
,
size
.
X
,
size
.
Y
,
server
);
}
}
Wow64DisableWow64FsRedirection
(
&
redir
);
Wow64DisableWow64FsRedirection
(
&
redir
);
res
=
CreateProcessW
(
conhost_path
,
cmd
,
NULL
,
NULL
,
TRUE
,
DETACHED_PROCESS
,
NULL
,
NULL
,
res
=
CreateProcessW
(
conhost_path
,
cmd
,
NULL
,
NULL
,
TRUE
,
DETACHED_PROCESS
|
EXTENDED_STARTUPINFO_PRESENT
,
&
si
.
StartupInfo
,
&
pi
);
NULL
,
NULL
,
&
si
.
StartupInfo
,
&
pi
);
HeapFree
(
GetProcessHeap
(),
0
,
si
.
lpAttributeList
);
Wow64RevertWow64FsRedirection
(
redir
);
Wow64RevertWow64FsRedirection
(
redir
);
NtClose
(
server
);
NtClose
(
server
);
if
(
!
res
)
if
(
!
res
)
...
...
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