Skip to content
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

Avoid calling setenv with identical previous contents. #27

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,19 @@ pub fn try_init_ssl_cert_env_vars() -> bool {
// 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);
put(ENV_CERT_FILE, path);
}
if let Some(path) = &cert_dir {
env::set_var(ENV_CERT_DIR, path);
put(ENV_CERT_DIR, path);
}

fn put(var: &str, path: &Path) {
// Avoid calling `setenv` if the variable already has the same contents. This avoids a
// crash when called from out of perl <5.38 (Debian Bookworm is at 5.36), as old versions
// of perl tend to manipulate the `environ` pointer directly.
if env::var_os(var).as_deref() != Some(path.as_os_str()) {
env::set_var(var, path);
}
}

cert_file.is_some() || cert_dir.is_some()
Expand Down