git2-rs
git2-rs copied to clipboard
Initialization function sets environment variables
This function is called by pretty much everything in this crate.
fn init() {
static INIT: Once = Once::new();
INIT.call_once(|| {
openssl_env_init();
});
raw::init();
}
The problem is that openssl_env_init sets environment variables.
pub fn try_init_ssl_cert_env_vars() -> bool {
let ProbeResult { cert_file, cert_dir } = probe();
// we won't be overwriting existing env variables because if they're valid probe() will have
// returned them unchanged
if let Some(path) = &cert_file {
env::set_var(ENV_CERT_FILE, path);
}
if let Some(path) = &cert_dir {
env::set_var(ENV_CERT_DIR, path);
}
cert_file.is_some() || cert_dir.is_some()
}
This is a problem because set_var is unsound in multi-threaded programs, see https://internals.rust-lang.org/t/synchronized-ffi-access-to-posix-environment-variable-functions/15475?u=xfix. When git is initialized there is no guarantee that there aren't multiple threads involved.
This call is causing other troubles as well. Even the documentation says that this should be called wisely. It breaks cargo for me.
Related: https://github.com/alexcrichton/openssl-probe/issues/37