jobserver-rs icon indicating copy to clipboard operation
jobserver-rs copied to clipboard

Client::configure is unsafe

Open glandium opened this issue 4 years ago • 1 comments

If you do something like:

if let Some(client) = unsafe { jobserver::Client::from_env() } {
    client.configure(&mut cmd);
}

Where cmd is an existing Command.

By the time you execute the command and the pre_cmd that Client::configure set up, the Client instance has already been dropped. And dropping the Client actually closes the file descriptors (which is documented in Client::from_env. So by the time the pre-command executes, the file descriptors are either closed, or worse, were opened for something else.

It seems like Client::configure should have an explicit requirement on the lifetime of the command not exceeding that of the client.

glandium avatar Jul 18 '20 06:07 glandium

I think we could probably fix this by closing over the necessary state in the closure we pass to Command, it should all be in an internal Arc anyway

alexcrichton avatar Jul 20 '20 14:07 alexcrichton