-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GenerateConsoleCtrlEvent should not succeed when dwProcessGroupId is not a group ID #335
Comments
Now that the source is published, I can finally see that the change was clearly intentional, but I can't imagine who this was meant to help, since it fails in all cases. If Next it sets the given group ID as the
In the case where we target a process ID that's not a group ID but both it and its parent are attached to the console, then
As mentioned above, if the target isn't attached to the console but its parent is, then a dummy process record is added via
Since the process isn't connected to the console, Once the process exists, subsequent calls to |
Rephrasing a little in terms of impact: if The following is a simple repro which will launch notepad and call To use:
Based on eryksun's analysis, I made the following change, which "fixes" the behavior by not aborting signal handling when it encounters a bogus process. I don't think this is the "real" fix but it confirms that this is the problem.
|
I can verify the repro works on my Windows 10 installation as well. This seems like a pretty serious bug as Python relies on the exact same |
This could make it impossible to send a console control event from one console to another without also sending the control even to the current console. Eg:
The above would be impossible, and replacing |
There's another bug in RETURN_IF_NTSTATUS_FAILED((NtPrivApi::s_GetProcessParentId(&ProcessId))); If the internal >>> _winapi.GenerateConsoleCtrlEvent(0, 123456)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 115, in GenerateConsoleCtrlEvent
OSError: [WinError 11] An attempt was made to load a program with an incorrect format. Removing the mistaken code that violates the 30-year-old documentation of The code mistakenly returns a raw To make matters worse, code in The code in Also, the status value should be initialized as |
The
dwProcessGroupId
parameter ofGenerateConsoleCtrlEvent
should be limited to process groups or the special group 0 that means all process attached to the console. If no process belongs to the given group ID, the call should fail withERROR_INVALID_PARAMETER
. This used to be the case (and the code I've read in ReactOS seems as simple as this), but at some point (XP?) it was changed to succeed for any process ID if it happens to be a child of a process that's attached to the console. I have to assume this was intentional, though I don't think any explanation could get me to agree with the intent.If the target process is attached to the console, it behaves the same as the group 0 case, which contributes to misunderstandings about this function. Otherwise it's relatively benign. The truly weird and buggy aspect of this is that it succeeds for a child of a process that's attached to the console even if the child itself is not attached to the console (e.g. a non-console process, or one created with
DETACHED_PROCESS
,CREATE_NEW_CONSOLE
, orCREATE_NO_WINDOW
). In this case the call appears to do nothing. But on closer inspection, we see that the target process gets added to the console's process list (i.e.GetConsoleProcessList
) even though it's not attached to the console, and in Process Explorer we see that conhost.exe has a handle for the process. If the process terminates, the console doesn't get notified, so this handle for a defunct process stays in the console's list. Apparently this puts the console's process list in a bad state. All processes that were added before the defunct process are subsequently invisible toGenerateConsoleCtrlEvent
, even if we target group 0.The text was updated successfully, but these errors were encountered: