-
Notifications
You must be signed in to change notification settings - Fork 120
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
Dereferencing std::vector::end using boost::process::limit_handles flag on Windows #200
Comments
We've also ran into this issue. I guess the author's intention was to apply the filtering, and thus remove all non-inherited handles, to the original list of handles the process has open ( |
Looking at it more closely if the process PID exceeds 65535 (USHRT_MAX) then the get_handles call will not return any handles for the current process. As it's undocumented it's hard to hunt down but it looks like the I think it would be safer to possibly use UpdateProcThreadAttribute() (at least for vista +) as suggested originally. It seems a bit unnecessary to iterate over all the system handles in order to limit the handles inherited by a process when UpdateProcThreadAttribute() is supported. |
Please fix at least the undefined behavior, it's been 2 years already. "65535+ PID" is another issue and must be fixed seperately. |
got the same crash on starting process on Windows like
the fix that helps me is
|
I've noticed while using
boost::process::limit_handles
that the code seems to be attempting to dereference std::vector::end which ultimately ends up with undefined behavior. We can see hereIf the
iterator != all_handles.end()
then it was found and set the value to::boost::winapi::INVALID_HANDLE_VALUE_
. Otherwise dereference the iterator into GetHandleInformation, however the iterator will equal all_handles.end(). It also seems that if this is the case there's no point in settingitr
to::boost::winapi::INVALID_HANDLE_VALUE_
as it already is not present in all_handles list and therefore::boost::winapi::SetHandleInformation
won't be called on it anyway. It seems the additionalelse if
is redundant?Ordinarily if this code is being called you would expect at least 1 handle to be present (for the pipe) in the calling process and therefore wouldn't normally run into this error but I am also seeing it's possible for get_handles() to return nothing and this then seems to cause an access violation.
The text was updated successfully, but these errors were encountered: